react-pure-component-starter icon indicating copy to clipboard operation
react-pure-component-starter copied to clipboard

Webpack error "Unexpected token"

Open gumarm opened this issue 8 years ago • 8 comments

Hi,

I just cloned and tried to build the starter kit, but there seems to be an error with webpack.

ERROR in ./source/components/hello/index.js Module parse failed: C:.../source\components\hello\index.js Unexpected token (9:6) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (9:6)

I have tracked down the cause of this to the webpack.config.dev.js and webpack.config.prod.js files. The line that triggers the error is : include: path.join(__dirname, 'source')

As soon as I remove that line (actually replacing it with an exclude of node_modules instead), the projet build and runs perfectly.

Do you have any idea what causes this ?

Thanks!

gumarm avatar Jan 10 '17 01:01 gumarm

Did you remember to run npm install?

ericelliott avatar Feb 13 '17 18:02 ericelliott

I ran npm install but still getting this issue.

ongerit avatar Feb 15 '17 03:02 ongerit

Same for me, packages were installed and everything worked once I replaced the include line in the webpack config.

gumarm avatar Feb 15 '17 13:02 gumarm

I ran into the same issue. Thank you @gumarm for adding your workaround.

I too am curious as to what could be causing this.

As a reference, here is the loaders block from my webpack.config.dev.js:

loaders: [{
  test: /\.js$/,
  loader: 'babel-loader',
  exclude: /node_modules/,
  query: {
    presets: ['es2015', 'stage-0', 'react']
  }
}]

I am on a windows machine, node v7.6.0, npm v4.1.2

Thank you Eric for all you do in the tech community!

higgins1b avatar Apr 25 '17 18:04 higgins1b

@higgins1b You can also replace include: path.join(__dirname, 'source') with an include on the hard-coded path like include: 'path_here'. I've had this issue with using path.join on Windows machines before.

gumarm avatar Apr 25 '17 19:04 gumarm

I'm open to a PR replacing path.join with an exclude of node_modules, but I'm curious about why path.join doesn't work on Windows. Have any of you searched the Node repo for a corresponding issue and possible resolutions?

ericelliott avatar Apr 26 '17 00:04 ericelliott

Are we sure that the path module is cross platform compatible?

Burgi0101 avatar Apr 26 '17 06:04 Burgi0101

@Burgi0101 It should at least be compatible with Windows according to Node's documentation: https://nodejs.org/api/path.html

@ericelliott I'll search around if I can find a reason as to why it doesn't work, if I don't find anything I'll send a PR for the workaround!

Thanks for your time guys!

gumarm avatar Apr 26 '17 13:04 gumarm