In my React app, executing npm run build
results in:
Module parse failed: ...\node_modules\npm\bin\npm-cli.js Unexpected character '#' (1:0)
So according to this StackOverflow answer, the first line #!/usr/bin/env node
in npm-cli.js
was the issue. To resolve this, I could make use of BannerPlugin (docs), which I did:
Location: webpack.config.prod.js
/ webpack.config.dev.js
module.exports = {
...
plugins: [
...
new webpack.BannerPlugin({
banner: "#!/usr/bin/env node",
raw: true
})
],
...
};
Now, executing npm run build
again results in:
...\node_modules\webpack\lib\BannerPlugin.js:9
if(str.indexOf("\n") < 0) return "/*! " + str + " */";
^
TypeError: str.indexOf is not a function
at wrapComment (...\node_modules\webpack\lib\BannerPlugin.js:9:9)
...
Reading the comments in this StackOverflow question, I concluded that str
is not a valid object. How would one resolve this issue without having to modify BannerPlugin.js
, or bypass the use of BannerPlugin entirely?
Edit 1: Here is the entire webpack.config.dev.js and webpack.config.prod.js as a Pastebin. The version of the webpack should be "webpack@1.14.0
" as found in the webpack package.json
(npm list webpack
did not work).
Edit 2: I have bypassed the use of BannerPlugin as seen here.