问题描述
我将Angular的版本从4更新为5.以下是屏幕截图,我按照链接
package.json
文件
{"name":"VotingWebsite",私人":是的,"version":"0.0.0",脚本":{"test":业力启动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/茉莉花":"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",茉莉花芯":"2.9.1","jquery":"3.3.1","json-loader":"0.5.7",业力":"2.0.0","karma-chai":"0.1.0",业力铬发射器":"2.2.0","karma-cli":"1.0.1",业力茉莉花":"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"}}
我收到错误消息
未捕获的错误:找不到模块"popper.js"在webpackMissingModule(vendor.js?v = g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82252)在vendor.js?v = g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82252< anonymous>.(vendor.js?v = g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82255)在__webpack_require__(vendor.js?v = g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:21)< anonymous>.(来自DLL引用vendor_19596f3f8868cecda14a:1的bootstrap.js)在__webpack_require__(bootstrap acba0f7e8b1985fd75ba:678)在fn(bootstrap acba0f7e8b1985fd75ba:88)< anonymous>.(process-update.js:146)在__webpack_require__(bootstrap acba0f7e8b1985fd75ba:678)在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)=>{//客户端和服务器端捆绑包都具有相同的配置const isDevBuild =!(env&& env.prod);const sharedConfig = {stats:{modules:false},上下文:__ dirname,解析:{扩展名:['.js','.ts']},输出: {文件名:"[name] .js",publicPath:'dist/'//Webpack开发者中间件(如果启用)处理对该URL前缀的请求},模块: {规则:[{test:/\.ts$/,使用:isDevBuild吗?['awesome-typescript-loader?silent = true','angular2-template-loader','angular2-router-loader']:'@ ngtools/webpack'},{test:/\.html$/,使用:'html-loader?minimize = false'},{测试:/\.css$/,使用:['to-string-loader',isDevBuild吗?'css-loader':'css-loader?minimize']},{test:/\.(png|jpg|jpeg|gif|svg)$/,使用:'url-loader?limit = 25000'}]},插件:[new CheckerPlugin()]};//适用于在浏览器中运行的客户端捆绑包的配置const clientBundleOutputDir ='./wwwroot/dist';const clientBundleConfig = merge(sharedConfig,{条目:{'main-client':'./ClientApp/boot.browser.ts'},输出:{path:path.join(__ dirname,clientBundleOutputDir)},插件:[新的webpack.DllReferencePlugin({上下文:__ dirname,清单:require('./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中运行的服务器端(prerendering)捆绑包的配置const serverBundleConfig = merge(sharedConfig,{解析:{mainFields:['main']},条目:{'main-server':'./ClientApp/boot.server.ts'},插件:[新的webpack.DllReferencePlugin({上下文:__ dirname,清单:require('./ClientApp/dist/vendor-manifest.json'),sourceType:'commonjs2',名称:"./vendor"})] .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')},目标:节点",devtool:"inline-source-map"});返回[clientBundleConfig,serverBundleConfig];};
它与asp.net核心Visual Studio 2017中的angular 4模板完美配合.当我将该程序包更新为Angular 5时,出现如上所述的错误.
我试图用Google搜索解决方案,但找不到解决方案.
我通过以下方式解决了项目中的相同问题:
1)将popper.js添加到package.json文件(我已经看到了),然后运行"npm install":
"popper.js":"^ 1.12.9",
2)在导入引导程序语句之前,在boot.browser.js文件中添加Import popper.js语句:
import'popper.js';导入'bootstrap';
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核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!