gpt4 book ai didi

javascript - 无法解析 "app.js"- Webpack

转载 作者:行者123 更新时间:2023-11-29 21:07:18 27 4
gpt4 key购买 nike

问题

所以,我正在使用 Webpack 和 ES6 开发一个网络应用程序。当我尝试运行 Webpack 时,它告诉我它无法解析“app.js”。我已经在互联网上寻找解决方案,但我找不到一个,有人可以帮助我吗?完整错误是:

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(空)

ma​​in.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"
}
}

最佳答案

当导入既不是绝对路径(以/开头)也不是明确的相对路径(以./../开头) >),它被解析为一个模块,这意味着它是 Loading from node_modules Folders .

你的app.js不在node_modules中,所以需要改成相对路径(假设和main.js在同一个目录下) ):

require("./app.js");

Webpack 遵循 Node.js 的导入行为,但它也允许您使用 resolve.modules 更改它。选项。

关于javascript - 无法解析 "app.js"- Webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43434251/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com