【问题标题】:Angular cli project not building when nesting code inside another folder in src将代码嵌套在 src 中的另一个文件夹中时,Angular cli 项目未构建
【发布时间】:2017-09-06 10:21:25
【问题描述】:

我创建了一个 Angular cli 项目。我的代码位于 src 文件夹中。我现在在 src 中创建了一个名为 client 的子文件夹,并将所有代码移到了 client 中。 我还更新了 angular-cli.json 如下:

  apps": [
{
  "root": "src/client",

不知何故,我的应用程序没有构建,并且出现以下错误:

D:/ccw-dev/ccw-ng/src/client/app/app-routing.module.ts (1,26) 中的错误:找不到模块“@angular/core”。 这发生在所有文件中,因为没有一个模块是可访问的。 我的错误是什么?

【问题讨论】:

  • src里面有app文件夹吗,你的文件夹结构是什么
  • 尝试删除node modules文件夹并再次运行npm install,路径可能需要更新
  • 要么将 app.module.ts 保存在 app 文件夹中,其他一切都会到位

标签: angular angular-cli


【解决方案1】:

Angular 在 src 目录中的几个文件中使用相对 URL,请参阅 tsconfig.app.json 和 tsconfig.spec.json。将代码移动到子目录后,您需要手动修改这些文件。

如果您知道在生成项目之前希望 src/client 成为根目录,则无需手动执行:ng new my-proj --source-dir=src/client

【讨论】:

    猜你喜欢
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    • 2017-04-19
    相关资源
    最近更新 更多