找不到模块“popper.js"Angular 5 Visual Studio 2017 asp.net 核心 [英] Cannot find module "popper.js" Angular 5 Visual Studio 2017 asp.net core

查看:35
本文介绍了找不到模块“popper.js"Angular 5 Visual Studio 2017 asp.net 核心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Angular 的版本从 4 更新到 5.下面是屏幕截图,我按照链接

package.json 文件

<代码>{"name": "投票网站",私人":真的,版本":0.0.0",脚本":{"test": "karma start ClientApp/test/karma.conf.js"},开发依赖":{"@angular/animations": "5.2.1","@angular/common": "5.2.1","@angular/compiler": "5.2.1","@angular/compiler-cli": "5.2.1","@angular/core": "5.2.1","@angular/forms": "5.2.1","@angular/http": "5.2.1","@angular/platform-b​​rowser": "5.2.1","@angular/platform-b​​rowser-dynamic": "5.2.1","@angular/platform-server": "5.2.1","@angular/router": "5.2.1","@ngtools/webpack": "1.9.5","@types/chai": "4.1.1","@types/jasmine": "2.8.5","@types/webpack-env": "1.13.3","angular2-router-loader": "0.3.5","angular2-template-loader": "0.6.2","aspnet-prerendering": "^3.0.1","aspnet-webpack": "^2.0.1","awesome-typescript-loader": "3.4.1","popper.js": "^1.12.5","bootstrap": "4.0.0","柴": "4.1.2","css": "2.2.1","css-loader": "0.28.9","es6-shim": "0.35.3",事件源polyfill":0.0.12","expose-loader": "0.7.4","extract-text-webpack-plugin": "3.0.2",文件加载器":1.1.6","html-loader": "0.5.5","isomorphic-fetch": "2.2.1","jasmine-core": "2.9.1","jquery": "3.3.1","json-loader": "0.5.7","业力": "2.0.0","karma-chai": "0.1.0","karma-chrome-launcher": "2.2.0","karma-cli": "1.0.1","karma-jasmine": "1.1.1","karma-webpack": "2.0.9","preboot": "6.0.0-beta.1","raw-loader": "0.5.1",反射元数据":0.1.12","rxjs": "5.5.6",样式加载器":0.19.1","to-string-loader": "1.1.5","打字稿": "2.6.2","url-loader": "0.6.2","webpack": "3.10.0","webpack-hot-middleware": "2.21.0","webpack-merge": "4.1.1",zone.js":0.8.20"}}

我收到一个错误

未捕获的错误:找不到模块popper.js"在 webpackMissingModule (vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82252)在 vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82252在对象<匿名>(vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82255)在 __webpack_require__ (vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:21)在对象<匿名>(来自 dll-reference vendor_19596f3f8868cecda14a:1 的 bootstrap.js)在 __webpack_require__ (引导 acba0f7e8b1985fd75ba:678)在 fn (引导 acba0f7e8b1985fd75ba:88)在对象<匿名>(process-update.js:146)在 __webpack_require__ (引导 acba0f7e8b1985fd75ba:678)在 fn (引导 acba0f7e8b1985fd75ba:88)

Webpack.config.js

const path = require('path');const webpack = require('webpack');const merge = require('webpack-merge');const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;module.exports = (env) =>{//客户端和服务器端包的共同配置const isDevBuild = !(env && env.prod);const sharedConfig = {统计信息:{模块:假},上下文:__dirname,解决:{扩展名:['.js','.ts']},输出: {文件名:'[名称].js',publicPath: 'dist/'//Webpack 开发中间件,如果启用,处理对这个 URL 前缀的请求},模块: {规则: [{ 测试:/\.ts$/,使用:isDevBuild ?['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] : '@ngtools/webpack' },{ 测试:/\.html$/, 使用: 'html-loader?minimize=false' },{ 测试:/\.css$/, 使用: [ 'to-string-loader', isDevBuild ?'css-loader' : 'css-loader?minimize' ] },{ 测试:/\.(png|jpg|jpeg|gif|svg)$/,使用:'url-loader?limit=25000' }]},插件:[新的 CheckerPlugin()]};//适合在浏览器中运行的客户端包的配置const clientBundleOutputDir = './wwwroot/dist';const clientBundleConfig = 合并(共享配置,{条目:{'主客户端':'./ClientApp/boot.browser.ts'},输出:{ path: path.join(__dirname, clientBundleOutputDir) },插件: [新的 webpack.DllReferencePlugin({上下文:__dirname,清单:需要('./wwwroot/dist/vendor-manifest.json')})].concat(isDevBuild ? [//仅适用于开发构建的插件新的 webpack.SourceMapDevToolPlugin({filename: '[file].map',//如果您更喜欢内联源映射,请删除此行moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]')//将源映射条目指向磁盘上的原始文件位置})] : [//仅适用于生产构建的插件新的 webpack.optimize.UglifyJsPlugin(),新的 AngularCompilerPlugin({tsConfigPath: './tsconfig.json',entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'),排除:['./**/*.server.ts']})])});//配置适合在 Node 中运行的服务器端(预渲染)包const serverBundleConfig = 合并(共享配置,{解析:{ mainFields: ['main'] },条目:{'主服务器':'./ClientApp/boot.server.ts'},插件: [新的 webpack.DllReferencePlugin({上下文:__dirname,清单:需要('./ClientApp/dist/vendor-manifest.json'),源类型:'commonjs2',名称:'./供应商'})].concat(isDevBuild ? [] : [//仅适用于生产构建的插件新的 AngularCompilerPlugin({tsConfigPath: './tsconfig.json',entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'),排除:['./**/*.browser.ts']})]),输出: {libraryTarget: 'commonjs',路径:path.join(__dirname, './ClientApp/dist')},目标:'节点',开发工具:'内联源映射'});返回 [clientBundleConfig, serverBundleConfig];};

它与 asp.net core Visual Studio 2017 中的 angular 4 模板完美配合.当我将包更新到 Angular 5 时,我收到了如上所述的错误.

我试图用谷歌搜索解决方案,但无法找到解决方案.

解决方案

我在我的项目中修复了同样的问题:

1) 将 popper.js 添加到 package.json 文件中(我看到你已经有了这个),然后运行npm install":

"popper.js": "^1.12.9",

2) 在 boot.browser.js 文件中添加一个 Import popper.js 语句在 import bootstrap 语句之前:

import 'popper.js';导入引导程序";

I updated my Angular's verision from 4 to 5. Below is the screenshot, I followed the instruction as per the link http://www.talkingdotnet.com/upgrade-angular-4-app-angular-5-visual-studio-2017/

package.json file

{
  "name": "VotingWebsite",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "test": "karma start ClientApp/test/karma.conf.js"
  },
  "devDependencies": {
    "@angular/animations": "5.2.1",
    "@angular/common": "5.2.1",
    "@angular/compiler": "5.2.1",
    "@angular/compiler-cli": "5.2.1",
    "@angular/core": "5.2.1",
    "@angular/forms": "5.2.1",
    "@angular/http": "5.2.1",
    "@angular/platform-browser": "5.2.1",
    "@angular/platform-browser-dynamic": "5.2.1",
    "@angular/platform-server": "5.2.1",
    "@angular/router": "5.2.1",
    "@ngtools/webpack": "1.9.5",
    "@types/chai": "4.1.1",
    "@types/jasmine": "2.8.5",
    "@types/webpack-env": "1.13.3",
    "angular2-router-loader": "0.3.5",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "^2.0.1",
    "awesome-typescript-loader": "3.4.1",
    "popper.js": "^1.12.5",
    "bootstrap": "4.0.0",
    "chai": "4.1.2",
    "css": "2.2.1",
    "css-loader": "0.28.9",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.12",
    "expose-loader": "0.7.4",
    "extract-text-webpack-plugin": "3.0.2",
    "file-loader": "1.1.6",
    "html-loader": "0.5.5",
    "isomorphic-fetch": "2.2.1",
    "jasmine-core": "2.9.1",
    "jquery": "3.3.1",
    "json-loader": "0.5.7",
    "karma": "2.0.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.1.1",
    "karma-webpack": "2.0.9",
    "preboot": "6.0.0-beta.1",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.12",
    "rxjs": "5.5.6",
    "style-loader": "0.19.1",
    "to-string-loader": "1.1.5",
    "typescript": "2.6.2",
    "url-loader": "0.6.2",
    "webpack": "3.10.0",
    "webpack-hot-middleware": "2.21.0",
    "webpack-merge": "4.1.1",
    "zone.js": "0.8.20"
  }
}

I am getting an error as

Uncaught Error: Cannot find module "popper.js"
    at webpackMissingModule (vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82252)
    at vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82252
    at Object.<anonymous> (vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82255)
    at __webpack_require__ (vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:21)
    at Object.<anonymous> (bootstrap.js from dll-reference vendor_19596f3f8868cecda14a:1)
    at __webpack_require__ (bootstrap acba0f7e8b1985fd75ba:678)
    at fn (bootstrap acba0f7e8b1985fd75ba:88)
    at Object.<anonymous> (process-update.js:146)
    at __webpack_require__ (bootstrap acba0f7e8b1985fd75ba:678)
    at fn (bootstrap acba0f7e8b1985fd75ba:88)

Webpack.config.js

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;

module.exports = (env) => {
    // Configuration in common to both client-side and server-side bundles
    const isDevBuild = !(env && env.prod);
    const sharedConfig = {
        stats: { modules: false },
        context: __dirname,
        resolve: { extensions: [ '.js', '.ts' ] },
        output: {
            filename: '[name].js',
            publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
        },
        module: {
            rules: [
                { test: /\.ts$/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] : '@ngtools/webpack' },
                { test: /\.html$/, use: 'html-loader?minimize=false' },
                { test: /\.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },
                { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
            ]
        },
        plugins: [new CheckerPlugin()]
    };

    // Configuration for client-side bundle suitable for running in browsers
    const clientBundleOutputDir = './wwwroot/dist';
    const clientBundleConfig = merge(sharedConfig, {
        entry: { 'main-client': './ClientApp/boot.browser.ts' },
        output: { path: path.join(__dirname, clientBundleOutputDir) },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./wwwroot/dist/vendor-manifest.json')
            })
        ].concat(isDevBuild ? [
            // Plugins that apply in development builds only
            new webpack.SourceMapDevToolPlugin({
                filename: '[file].map', // Remove this line if you prefer inline source maps
                moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
            })
        ] : [
            // Plugins that apply in production builds only
            new webpack.optimize.UglifyJsPlugin(),
            new AngularCompilerPlugin({
                tsConfigPath: './tsconfig.json',
                entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'),
                exclude: ['./**/*.server.ts']
            })
        ])
    });

    // Configuration for server-side (prerendering) bundle suitable for running in Node
    const serverBundleConfig = merge(sharedConfig, {
        resolve: { mainFields: ['main'] },
        entry: { 'main-server': './ClientApp/boot.server.ts' },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require('./ClientApp/dist/vendor-manifest.json'),
                sourceType: 'commonjs2',
                name: './vendor'
            })
        ].concat(isDevBuild ? [] : [
            // Plugins that apply in production builds only
            new AngularCompilerPlugin({
                tsConfigPath: './tsconfig.json',
                entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'),
                exclude: ['./**/*.browser.ts']
            })
        ]),
        output: {
            libraryTarget: 'commonjs',
            path: path.join(__dirname, './ClientApp/dist')
        },
        target: 'node',
        devtool: 'inline-source-map'
    });

    return [clientBundleConfig, serverBundleConfig];
};

It was working perfectly with angular 4 template in asp.net core Visual Studio 2017. When I update the package to Angular 5, I'm getting an error as described above.

I tried to google the solution, but not able to find the solution.

解决方案

I fixed the same problem in my project by:

1) Adding popper.js to the package.json file (I see you already have this), and running "npm install":

"popper.js": "^1.12.9",

2) Adding an Import popper.js statement to the boot.browser.js file before the import bootstrap statement:

import 'popper.js';
import 'bootstrap';

这篇关于找不到模块“popper.js"Angular 5 Visual Studio 2017 asp.net 核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆