gpt4 book ai didi

angular - 构建 Angular CLI 时出错

转载 作者:行者123 更新时间:2023-12-05 08:42:11 25 4
gpt4 key购买 nike

我在尝试构建我的 Angular 2 项目时遇到问题。当我调用 ng build ,构建器正在将路由路径验证为模块,并说它不存在:

无法从“C:/Users/bruno.martins/git/disciples-ui/src/app/app.module.ts”解析“app/membros/membro.module”中的错误。

C:\Users\bruno.martins\git\disciples-ui>npm install

> disciples-ui@0.0.0 postinstall C:\Users\bruno.martins\git\disciples-ui
> ng build --prod

As a forewarning, we are moving the CLI npm package to "@angular/cli" with the next release,
which will only support Node 6.9 and greater. This package will be officially deprecated
shortly after.

To disable this warning use "ng set --global warnings.packageDeprecation=false".

fallbackLoader option has been deprecated - replace with "fallback"
loader option has been deprecated - replace with "use"
fallbackLoader option has been deprecated - replace with "fallback"
loader option has been deprecated - replace with "use"
fallbackLoader option has been deprecated - replace with "fallback"
loader option has been deprecated - replace with "use"
fallbackLoader option has been deprecated - replace with "fallback"
loader option has been deprecated - replace with "use"
Hash: d8f6b3f0c56af167dadf
Time: 16957ms
chunk {0} polyfills.97e9eeda4d76d39a40b8.bundle.js (polyfills) 239 kB {4} [initial] [rendered]
chunk {1} main.c2b4bf4bdc30f5037cb6.bundle.js (main) 13.6 kB {3} [initial] [rendered]
chunk {2} styles.d41d8cd98f00b204e980.bundle.css (styles) 69 bytes {4} [initial] [rendered]
chunk {3} vendor.45864682c5b5d47e6aa5.bundle.js (vendor) 2.35 MB [initial] [rendered]
chunk {4} inline.30690479fd56d04d5cd5.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in Could not resolve "app/membros/membro.module" from "C:/Users/bruno.martins/git/disciples-ui/src/app/app.module.ts".

问题出在这里:

RouterModule.forRoot([
{
path: 'membro',
loadChildren: 'app/membros/membro.module#MembroModule'
},
{
path : 'testador',
loadChildren: 'app/testador/testador.module#TestadorModule'
}
])

如果我删除这个“loadChildren”,构建运行正常!实际上,这是正确的,因为应用程序一开始就没有问题并且可以运行。我在 heroku 上部署这个应用程序,所以我必须使用 ng build在 Heroku(此命令也在本地给出错误);在本地,我只使用 npm start (应用程序使用它运行良好)。

这也是我的 package.json:

{
"name": "disciples-ui",
"version": "0.0.0",
"license": "",
"angular-cli": {},
"scripts": {
"build": "tsc -p src/",
"build:watch": "tsc -p src/ -w",
"build:e2e": "tsc -p e2e/",
"serve": "lite-server -c=bs-config.json",
"serve:e2e": "lite-server -c=bs-config.e2e.json",
"prestart": "npm run build",
"start": "concurrently \"npm run build:watch\" \"npm run serve\"",
"pree2e": "npm run build:e2e",
"e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
"preprotractor": "webdriver-manager update",
"protractor": "protractor protractor.config.js",
"pretest": "npm run build",
"test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
"pretest:once": "npm run build",
"test:once": "karma start karma.conf.js --single-run",
"lint": "tslint ./src/**/*.ts -t verbose",
"ng": "ng",
"postinstall": "ng build --prod",
"start-heroku": "node server.js"
},
"private": true,
"dependencies": {
"@angular/common": "~4.0.0",
"@angular/compiler": "~4.0.0",
"@angular/core": "~4.0.0",
"@angular/forms": "~4.0.0",
"@angular/http": "~4.0.0",
"@angular/platform-browser": "~4.0.0",
"@angular/platform-browser-dynamic": "~4.0.0",
"@angular/router": "~4.0.0",
"angular-in-memory-web-api": "~0.3.0",
"systemjs": "0.19.40",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"zone.js": "^0.8.4",
"ng": "0.0.0-rc6",
"angular-cli": "1.0.0-beta.28.3",
"@angular/compiler-cli": "~4.0.0"
},
"devDependencies": {
"@types/jasmine": "2.5.36",
"@types/node": "^6.0.46",
"canonical-path": "0.0.2",
"concurrently": "^3.2.0",
"core-js": "^2.4.1",
"express": "^4.15.2",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"lite-server": "^2.2.2",
"lodash": "^4.16.4",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"ts-helpers": "^1.1.1",
"tslint": "^3.15.1",
"typescript": "~2.2.1"
}
}

你们能帮帮我吗?

最佳答案

您的问题有两种可能的解决方案:

a) 使用正确的相对路径

这在此处描述:https://stackoverflow.com/a/48028980/5816097

使用 ./membros/membro.module#MembroModule 而不是 app/membro/membro.module#MembroModule

b) 在您的 compilerOptions

中提供 baseUrl

在您的 src/tsconfig.app.json 中,在 compilerOptions 下添加 baseUrl: "./":

{
...,
"compilerOptions": {
...,
baseUrl: "./"
}
}

关于angular - 构建 Angular CLI 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43633062/

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