[英]Webpack: Module not found: Error: Can't resolve 'app'
I am trying to migrate a project from RequireJS
to webpack
. 我正在尝试将项目从
RequireJS
迁移到webpack
。 I have most things set up, but when I try to run webpack
, I get the following error: 我已经设置了大多数东西,但是当我尝试运行
webpack
,出现以下错误:
Module not found: Error: Can't resolve 'app' in './app/scripts/views/public-views.js'."
My code is below. 我的代码如下。
public-views.js: public-views.js:
define([
'app',
'backbone.syphon',
], function(App) {
'use strict';
var Public = {};
Public.Home = Backbone.View.extend({
template: 'public/home',
initialize: function() {
//this.model.destroy();
this.render;
},
webpack.config.js webpack.config.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
target: 'web',
mode: 'development',
entry: {
appScript: './app/scripts/app.js',
public: './app/scripts/views/public-views.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, './app/dist')
},
resolve: {
modules: [
"node_modules",
path.resolve(__dirname, 'node_modules')
],
alias: {
'handlebars': '../../node_modules/handlebars/dist/handlebars'
},
extensions: ['.js']
},
plugins: [
new webpack.ProvidePlugin({
_: 'underscore'
})
],
module: {
rules: [
{
test: /\.handlebars$/,
exclude:/(node_modules)/,
loader:"handlebars-loader"
}
]
}
};
As far as I know, app
is not a module in NPM... so I assumed it was referring to the app.js
file. 据我所知,
app
不是NPM中的模块...所以我认为它是指app.js
文件。 What could I be missing? 我可能会缺少什么?
I was able to resolve this-- it seems like I needed to include "app" as an alias
after handlebars
. 我能够解决这个问题-似乎我需要在
handlebars
之后包括“ app”作为alias
。
This is what I used: 这是我使用的:
'app': path.resolve(__dirname, 'app') + '/scripts/app.js',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.