gpt4 book ai didi

angular - 找不到模块 Angular/动画

转载 作者:太空狗 更新时间:2023-10-29 16:52:17 24 4
gpt4 key购买 nike

我在 angular2 中使用 webpack,当我尝试运行我的应用程序时,我收到一条错误消息

Cannot find module "@angular/animations"

package.json

{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first",
"lint": "tslint ./app/**/*.ts -t verbose",
"lite": "lite-server",
"pree2e": "webdriver-manager update",
"test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
"test-once": "tsc && karma start karma.conf.js --single-run",
"tsc": "tsc",
"tsc:w": "tsc -w"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"@angular/common": "~2.4.0",
"@angular/compiler": "~2.4.0",
"@angular/core": "~2.4.0",
"@angular/forms": "~2.4.0",
"@angular/http": "~2.4.0",
"@angular/platform-browser": "~2.4.0",
"@angular/platform-browser-dynamic": "~2.4.0",
"@angular/router": "~3.4.0",
"angular-in-memory-web-api": "~0.2.4",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"systemjs": "0.19.40",
"zone.js": "^0.7.4"
},
"devDependencies": {
"awesome-typescript-loader": "^3.1.2",
"canonical-path": "0.0.2",
"concurrently": "^3.1.0",
"html-webpack-plugin": "^2.28.0",
"http-server": "^0.9.0",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine-html-reporter": "^0.2.2",
"lite-server": "^2.2.2",
"lodash": "^4.16.4",
"primeng": "^4.0.0-rc.1",
"protractor": "~4.0.14",
"reflect-metadata": "^0.1.10",
"rimraf": "^2.5.4",
"tslint": "^3.15.1",
"typescript": "~2.0.10",
"typings": "^2.1.0",
"webpack": "^2.2.1"
},
"repository": {},
"main": "index.js"
}

我的 webpack.config.js 文件是

var htmlWebPack = require('html-webpack-plugin');

module.exports = {
entry: "./app/main.ts",
output: {
path: 'dist',
filename: "bundle.js"
},
module: {
loaders: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader'
}
]
},
plugins: [
new htmlWebPack({
template: './index.html'
})
]
};

当我运行 npm start 之类的命令时,出现上述错误。

我什至尝试使用此命令安装 angular-animate

npm install angular-animate

这是我得到的错误信息

enter image description here

我还尝试用命令卸载angular-animate

npm uninstall angular-animate

但这对我没有帮助。

最佳答案

执行以下步骤使其工作:

  1. npm install @angular/animations@latest --save

  2. 从根 NgModule 中的“@angular/platform-b​​rowser/animations”导入“BrowserAnimationsModule”(否则,您的代码将编译并运行,但动画会触发错误)

  3. 在您的组件中,像这样从新包中导入 - "import { trigger, state, style, transition, animate } from '@angular/animations'; "

这对我有用。

关于angular - 找不到模块 Angular/动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42857345/

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