Been trying to use the react-spin npm module, but when I try and build a bundle.js with webpack, I receive the following error:
Module parse failed: /Users/nir/browsewidget/node_modules/react-spin/src/main.js Line 29: Unexpected token <
You may need an appropriate loader to handle this file type.
| render: function() {
| return (
| <span ref="container" />
| );
| }
@ ./js/widget.jsx 4:14-35
I am guessing that this module has jsx in it, but I don't understand why it can't be built? Does react-spin need some extra configuration when building a bundle?
Here is my full webpack.config.js:
module.exports = {
entry: "./js/widget.jsx",
output: {
path: __dirname,
filename: "bundle.js"
},
module: {
loaders: [
{
test: /\.jsx$/,
loader: 'jsx-loader?insertPragma=React.DOM&harmony'
}
]
},
externals: {
//don't bundle the 'react' npm package with our bundle.js
//but get it from a global 'React' variable
'react': 'React'
},
resolve: {
extensions: ['','.js','.jsx']
}
};
Been trying to use the react-spin npm module, but when I try and build a bundle.js with webpack, I receive the following error:
Module parse failed: /Users/nir/browsewidget/node_modules/react-spin/src/main.js Line 29: Unexpected token <
You may need an appropriate loader to handle this file type.
| render: function() {
| return (
| <span ref="container" />
| );
| }
@ ./js/widget.jsx 4:14-35
I am guessing that this module has jsx in it, but I don't understand why it can't be built? Does react-spin need some extra configuration when building a bundle?
Here is my full webpack.config.js:
module.exports = {
entry: "./js/widget.jsx",
output: {
path: __dirname,
filename: "bundle.js"
},
module: {
loaders: [
{
test: /\.jsx$/,
loader: 'jsx-loader?insertPragma=React.DOM&harmony'
}
]
},
externals: {
//don't bundle the 'react' npm package with our bundle.js
//but get it from a global 'React' variable
'react': 'React'
},
resolve: {
extensions: ['','.js','.jsx']
}
};
Share
Improve this question
asked Jul 13, 2015 at 1:58
ApathyBearApathyBear
9,60515 gold badges59 silver badges90 bronze badges
1 Answer
Reset to default 16Your loader is configured to only transform files that end in .jsx
:
test: /\.jsx$/,
(The dollar sign means end-of-string.)
You could change it to
test: /\.jsx?$/,
to transform both .js
and .jsx
files, but running every JavaScript file in node_modules
through the JSX loader will probably be fairly slow.
I believe you should be able to set an exclude
option of /node_modules/
and then an include
option for the specific module you care about (react-spin
), but the best solution is that packages not use JSX in the published version of the JavaScript—the author of react-spin
might be open to a pull request to this effect. (Edit: it appears there already is one, see thomasboyt/react-spin#3)
Finally, react-spin
is very small, so you man consider implementing it yourself in your own project (so that you don't have to worry about the webpack loader issues).