I’m getting an error with the twitter npm module when I run my react project using webpack with webpack-dev-server.
The error is:
*ERROR in ./~/twitter/~/request/~/har-validator/lib/schemas/timings.json
Module parse failed: /Users/peterkaminski/react-test/node_modules/twitter/node_modules/request/node_modules/har-validator/lib/schemas/timings.json Unexpected token (2:12)*
And I’m only getting it when I require twitter. My current project setup uses webpack and babel.
A solution I’ve tried coming up with is to just set up an express server to handle all my API calls while I render all the frontend with React. I’ve tried finding several tutorials for how to incorporate express with React, but none of them have been very clear.
What’s the best way to set up a project so you can include various node modules without getting these kinds of errors, and how do you go about running React with Express?
2
Answers
It seems your loader including node_modules and the library you are using have a JSON file which webpack is not able to bundle because you are missing json-loader
Install json-loader with
npm install json-loader
and configure your webpack to handle json files.Here is an example set up that allows you to get to developing (npm package and webpack included )
package.json
webpack.config
example server.js setup
given your react index.js, this is an example of importing what you need
in short, look at the entry point in webpack.config.js, you can see that it looks at ‘react-client/src’ and find index.js.
to run the script, simply do
npm start,
npm run webpack