javascript - Can't resolve "app.js" - Webpack - Stack Overflow

ProblemSo, i'm working a web app using Webpack and ES6. When I try to run Webpack, it tells me tha

Problem

So, i'm working a web app using Webpack and ES6. When I try to run Webpack, it tells me that it can't resolve "app.js". I've looked all across the internet for a solution, but I just couldn't find one, can someone help me? The Full error is:

ERROR in ./assets/js/main.js
Module not found: Error: Can't resolve 'app.js' in 'C:\Users\sidna\Dropbox\Dev Stuff\Web Apps\Mondrian Generator\assets\js'
 @ ./assets/js/main.js 4:0-17

webpack.config.js

module.exports = {
entry: './assets/js/main.js',
output: {
    filename: 'assets/js/build.js',
},
watch: true,
module: {
    loaders: [
        {
            test: /\.scss$/, loader: "style-loader!css-loader!sass-loader"
        },
        {
          test: /\.js$/,
          exclude: /node_modules/,
          use: {
            loader: 'babel-loader',
            options: {
              presets: ['env']
            }
          }
        }
    ],
}
};

app.js (Empty)

main.js

// SCRIPTS
require("app.js");

// STYLES
require("../css/large.scss");

package.json

{
"name": "mondrian-generator",
  "version": "1.0.0",
  "description": "Create your own Mondrian",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "ISC",
  "dependencies": {
    "css-loader": "^0.28.0",
    "style-loader": "^0.16.1",
    "webpack": "^2.4.1"
  },
  "devDependencies": {
    "babel-core": "^6.24.1",
    "babel-loader": "^6.4.1",
    "babel-preset-env": "^1.4.0",
    "node-sass": "^4.5.2",
    "sass-loader": "^6.0.3",
    "script-loader": "^0.7.0",
    "webpack": "^2.4.1"
  }
}

Problem

So, i'm working a web app using Webpack and ES6. When I try to run Webpack, it tells me that it can't resolve "app.js". I've looked all across the internet for a solution, but I just couldn't find one, can someone help me? The Full error is:

ERROR in ./assets/js/main.js
Module not found: Error: Can't resolve 'app.js' in 'C:\Users\sidna\Dropbox\Dev Stuff\Web Apps\Mondrian Generator\assets\js'
 @ ./assets/js/main.js 4:0-17

webpack.config.js

module.exports = {
entry: './assets/js/main.js',
output: {
    filename: 'assets/js/build.js',
},
watch: true,
module: {
    loaders: [
        {
            test: /\.scss$/, loader: "style-loader!css-loader!sass-loader"
        },
        {
          test: /\.js$/,
          exclude: /node_modules/,
          use: {
            loader: 'babel-loader',
            options: {
              presets: ['env']
            }
          }
        }
    ],
}
};

app.js (Empty)

main.js

// SCRIPTS
require("app.js");

// STYLES
require("../css/large.scss");

package.json

{
"name": "mondrian-generator",
  "version": "1.0.0",
  "description": "Create your own Mondrian",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "ISC",
  "dependencies": {
    "css-loader": "^0.28.0",
    "style-loader": "^0.16.1",
    "webpack": "^2.4.1"
  },
  "devDependencies": {
    "babel-core": "^6.24.1",
    "babel-loader": "^6.4.1",
    "babel-preset-env": "^1.4.0",
    "node-sass": "^4.5.2",
    "sass-loader": "^6.0.3",
    "script-loader": "^0.7.0",
    "webpack": "^2.4.1"
  }
}
Share Improve this question asked Apr 16, 2017 at 6:03 user7627319user7627319 1
  • 1 Clarify where do you put the files. – Tatsuyuki Ishi Commented Apr 16, 2017 at 6:08
Add a ment  | 

1 Answer 1

Reset to default 4

When the import is neither an absolute path (starting with /) nor explicitly a relative path (starting with ./ or ../), it is resolved as a module, which means it's Loading from node_modules Folders.

Your app.js is not in node_modules, so you need to change it to a relative path (assuming it's in the same directory as main.js):

require("./app.js");

Webpack follows the import behaviour of Node.js, but it also allows you to change it with the resolve.modules option.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745342688a4623400.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信