admin管理员组

文章数量:1429360

I'm trying to use webpack but i get an error

$ node_modules/.bin/webpack
Hash: d1aee5dc037997fae5a6
Version: webpack 3.4.1
Time: 31ms

ERROR in Entry module not found: Error: Can't resolve './assets/app.js' in 'D:\template\src'

It's my first time using webpack.

here is my script

const path = require('path');
const webpack = require('webpack');
module.exports = {
  context: path.resolve(__dirname, './src'),
  entry: {
    app: './assets/app.js',
  },
  output: {
    path: path.resolve(__dirname, './node_modules'),
    filename: '[name].bundle.js',
  },
};

My folder structure

I think i get the error here context: path.resolve(__dirname, './src'), I just don't know with what i replace that part.

I already read this and already try searching with google about how to use webpack. Any solutions ?.

  "devDependencies": {
    "buefy": "",
    "bulma": "",
    "vue": "^2.1.10",
    "webpack": "^3.4.1"
  },

I'm trying to use webpack but i get an error

$ node_modules/.bin/webpack
Hash: d1aee5dc037997fae5a6
Version: webpack 3.4.1
Time: 31ms

ERROR in Entry module not found: Error: Can't resolve './assets/app.js' in 'D:\template\src'

It's my first time using webpack.

here is my script

const path = require('path');
const webpack = require('webpack');
module.exports = {
  context: path.resolve(__dirname, './src'),
  entry: {
    app: './assets/app.js',
  },
  output: {
    path: path.resolve(__dirname, './node_modules'),
    filename: '[name].bundle.js',
  },
};

My folder structure

I think i get the error here context: path.resolve(__dirname, './src'), I just don't know with what i replace that part.

I already read this https://webpack.github.io/docs/tutorials/getting-started and already try searching with google about how to use webpack. Any solutions ?.

  "devDependencies": {
    "buefy": "",
    "bulma": "",
    "vue": "^2.1.10",
    "webpack": "^3.4.1"
  },
Share Improve this question edited Jul 28, 2017 at 15:29 Michael Jungo 33.1k4 gold badges95 silver badges87 bronze badges asked Jul 28, 2017 at 15:11 YVS1102YVS1102 2,7407 gold badges37 silver badges65 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

The context option defines the base directory that is used to resolve anything in the webpack config. You are using ./src/ as the base directory, so ./assets/app.js is resolved inside the src directory (it would technically be ./src/assets/app.js).

If no context is provided, webpack will use the current directory, which is what you want. You can remove context entirely from your config. You probably also want to output the bundle into a directory such as ./dist instead of into ./node_modules. Your config would be as follows.

const path = require('path');
const webpack = require('webpack');

module.exports = {
  entry: {
    app: './assets/app.js',
  },
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: '[name].bundle.js',
  },
};

You were looking at the webpack 1 docs, but you should use the newer docs, which are significantly better: Webpack - Getting Started.

本文标签: javascriptEntry module not found Can39t resolve 39assetsappjs39Stack Overflow