简体   繁体   English

Webpack:找不到模块:错误:无法解析“应用程序”

[英]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.

相关问题 Webpack 4:找不到入口模块中的错误:错误:无法解析'./src' - Webpack 4 : ERROR in Entry module not found: Error: Can't resolve './src' 找不到模块:错误:无法解析“ @ cycle / run” webpack 2.2.1 - Module not found: Error: Can't resolve '@cycle/run' webpack 2.2.1 webpack:找不到模块:错误:无法解析(使用相对路径) - webpack: Module not found: Error: Can't resolve (with relative path) Webpack:移动 webpack/react 文件的位置后,npm start “Module not found: Error: Can't resolve ...” - Webpack: npm start "Module not found: Error: Can't resolve ..." after moving location for webpack / react files 找不到模块:错误:无法解析'/ Users / jonathankuhl / Documents / Programming / node js / sandbox / webpack-app'中的'bundle.js' - Module not found: Error: Can't resolve 'bundle.js' in '/Users/jonathankuhl/Documents/Programming/node js/sandbox/webpack-app' 找不到Angular2 / 4模块:错误:无法解析“ .. \\ app”中的“三个”在解析“ .. \\ app”中的“三个” - Angular2/4 Module not found: Error: Can't resolve 'three' in '..\app' resolve 'three' in '..\app' 找不到模块:错误:无法解决“ avoriaz” - Module not found: Error: Can't resolve 'avoriaz' 未找到模块:错误:无法解析“ReactDOM” - Module not found: Error: Can't resolve 'ReactDOM' 找不到模块:错误:无法解析“加密” - Module not found: Error: Can't resolve 'crypto' 找不到模块:错误:无法解析 JSON - Module not found: Error: Can't resolve JSON
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM