Note that if you’re not using webpack, you’ll need to use relative paths. The require
function does not do node-style resolution or lookup.
As such:
-
require("module.js")
will fail because it’s not relative. Usingrequire("./module.js")
will work, assuming it’s in the same directory. - If you’ve got
node_modules/commonLib.js
, you’ll need to userequire("./node_modules/commonLib.js")
(assumingmain.js
is i
Be sure to also use module.exports = {/*...*/}
when doing this (ES6-style exports are not supported using this mechanism.)
If you want to use ES6 modules or have node-style resolution, a bundler is a requirement.