I set up a custom entry point in Webpack but am getting an error on this line of my React code:
import React from 'react';
Webpack is able to build it, but itsnt intercepting that path because Chrome gives me this console error:
Uncaught TypeError: Failed to resolve module specifier "react". Relative references must start with either "/", "./", or "../"
However, when I change the path as suggested to:
import React from './react';
Then webpack is unable to build and gives this error:
ERROR in ./path/to/my/file.js Module not found: Error: Can't resolve './react' in '/Users/me/Documents/GitHub/myProject/path/to/my @ ./path/to/my/file.js 3:0-28
And furthermore I get this Chrome console error:
GET http://localhost:9000/path/to/my/file/react net::ERR_ABORTED 404 (Not Found)
So webpack is looking for react in path/to/my/ instead of in node_modules as it should.
My webpack.config.js looks like this:
//snip
module.exports = {
entry: './path/to/my/file.js',
output: {
path: path.join(__dirname, '/build'),
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: path.join(__dirname, '/'),
port: 9000
},
//snip
}
and package.json
{
//snip
"main": "path/to/my/file.js",
//snip
}