TypeError: require is not a function at Object.mod

2020-04-11 16:46发布

问题:

while compiling node js project with gulp commmand below error occurs.

In public/js/app/app.node.js:

var fs = require('fs');
             ^

TypeError: require is not a function at Object.module.exports.map../file

I tried to implement react flux api calls with current project.

UPDATE:

this error has been removed after adding

new dwebpack.DefinePlugin({ "global.GENTLY": false })

but currently below error occuring.

return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                                                  ^

Error: ENOENT: no such file or directory, open '/types/mime.types'
    at Error (native)
    at Object.fs.openSync (fs.js:549:18)
    at Object.fs.readFileSync (fs.js:397:15)
    at Mime.load 

回答1:

answering own question is not right way to do it but as it will be helpful for other and as people look for answered question also so doing this.

as my issue with related to node version. i am on latest node version 4.0.0 and having issue with it.

so installed lower node version 0.12.7(which was specified in package.json of template code) and rebuilt by npm install solved it.

i have used https://www.npmjs.com/package/n package to install multiple node version and selecting the one i wanted to use.