2

When I run webpack --watch I got error of Cannot resolve module 'js/app.js'. And then my app.min.js did not complied when I do npm run dev.

I've created a git repo and this is my webpack.config.js

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');

module.exports = {
  context: path.join(__dirname, "src"),
  devtool: debug ? "inline-sourcemap" : null,
  entry: "js/app.js", //what's wrong with this line?
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-0']        }
      }
    ]
  },
  output: {
    path: __dirname + "src",
    filename: "app.min.js" //this is not even complied?
  },
  plugins: debug ? [] : [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  ],
};
3
  • 1
    entry: "./src/js/app.js", Commented Oct 1, 2016 at 16:05
  • @seti ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' ./src/js/app.js in /Users/myname/Documents/react-webpack-babel-starter/src Commented Oct 1, 2016 at 16:17
  • @seti any clue? Commented Oct 1, 2016 at 16:50

1 Answer 1

1

When using context, the entry path should start with a ./ followed by the relative path to the entry file.

module.exports = {
  context: path.join(__dirname, "src"),
  devtool: debug ? "inline-sourcemap" : null,
  entry: "./js/app.js",
  ...
}

Another way to resolve this is without using the context key and having an absolute path in the entry key like so:

entry: path.join(__dirname, 'src/js/app.js')
Sign up to request clarification or add additional context in comments.

9 Comments

Don't forget to install the babel-core npm module (npm i -D babel-core) or you will get the error ERROR in Cannot find module 'babel-core' @ multi main. Seems like you are missing it as a dependency in your package.json file.
Why babel core is needed?
This solved the first problem, my app.min.js is not produced still.
babel-core is the babel compiler itself, it’s what facilitates running your code through a series of transforms you define. It was previously bundled within a single package with babel-cli.
I followed a tutorial on youtube and this is the author's package.json, github.com/babel/babel/blob/master/packages/babel-core/… he did not use babel-core, are you sure babel core still needed?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.