I started using webpack2 (to be precise, v2.3.2 ) and after recreating my configuration, I continue to encounter a problem that I can't seem to solve (I apologize for the ugly dump in advance):
ERROR in ./src/main.js Module not found: Error: Can't resolve 'components/DoISuportIt' in '[absolute path to my repo]/src' resolve 'components/DoISuportIt' in '[absolute path to my repo]/src' Parsed request is a module using description file: [absolute path to my repo]/package.json (relative path: ./src) Field 'browser' doesn't contain a valid alias configuration aliased with mapping 'components': '[absolute path to my repo]/src/components' to '[absolute path to my repo]/src/components/DoISuportIt' using description file: [absolute path to my repo]/package.json (relative path: ./src) Field 'browser' doesn't contain a valid alias configuration after using description file: [absolute path to my repo]/package.json (relative path: ./src) using description file: [absolute path to my repo]/package.json (relative path: ./src/components/DoISuportIt) as directory [absolute path to my repo]/src/components/DoISuportIt doesn't exist no extension Field 'browser' doesn't contain a valid alias configuration [absolute path to my repo]/src/components/DoISuportIt doesn't exist .js Field 'browser' doesn't contain a valid alias configuration [absolute path to my repo]/src/components/DoISuportIt.js doesn't exist .jsx Field 'browser' doesn't contain a valid alias configuration [absolute path to my repo]/src/components/DoISuportIt.jsx doesn't exist [[absolute path to my repo]/src/components/DoISuportIt] [[absolute path to my repo]/src/components/DoISuportIt] [[absolute path to my repo]/src/components/DoISuportIt.js] [[absolute path to my repo]/src/components/DoISuportIt.jsx]
package.json
{ "version": "1.0.0", "main": "./src/main.js", "scripts": { "build": "webpack --progress --display-error-details" }, "devDependencies": { ... }, "dependencies": { ... } }
In terms of the browser he complains, the documentation I could find at this address: package-browser-field-spec . There is also documentation for web packages for it, but it seems to be enabled by default: aliasFields: ["browser"] . I tried adding a browser field to my package.json but that didn't seem to be of any benefit.
webpack.config.js
import path from 'path'; const source = path.resolve(__dirname, 'src'); export default { context: __dirname, entry: './src/main.js', output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js', }, resolve: { alias: { components: path.resolve(__dirname, 'src/components'), }, extensions: ['.js', '.jsx'], }, module: { rules: [ { test: /\.(js|jsx)$/, include: source, use: { loader: 'babel-loader', query: { cacheDirectory: true, }, }, }, { test: /\.css$/, include: source, use: [ { loader: 'style-loader' }, { loader: 'css-loader', query: { importLoader: 1, localIdentName: '[path]___[name]__[local]___[hash:base64:5]', modules: true, }, }, ], }, ], }, };
Src / main.js
import DoISuportIt from 'components/DoISuportIt';
Src / components / DoISuportIt / index.jsx
export default function() { ... }
For completeness .babelrc
{ "presets": [ "latest", "react" ], "plugins": [ "react-css-modules" ], "env": { "production": { "compact": true, "comments": false, "minified": true } }, "sourceMaps": true }
What am I doing wrong / missing?