2

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.

Wouter Vanherck
  • 2,070
  • 3
  • 27
  • 41

1 Answers1

-1

I know this is old now but just found it myself so for anyone else I suspect you have the new parameter layout with an old version of BannerPlugin. For webpack 1 it took banner as the first parameter, not named. From 2 or 3 it takes an object.

For you this would be:

new webpack.BannerPlugin('#!/usr/bin/env node', { raw: true })

Webpack 3 would be what you have:

new webpack.BannerPlugin({ banner: '#!/usr/bin/env node', raw: true })
chookie
  • 441
  • 6
  • 12