简体   繁体   中英

Can't create an Angular 5 project using angular-cli

I'm trying to create a new Angular 5 project. I've installed @angular/cli version 1.6.3 and typed:

ng new project --routing

After everything has been installed I did:

cd project
ng build

And got the following errors:

Module build failed: Error: d:...\\project\\src\\main.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

Module build failed: Error: d:...\\project\\src\\polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

There are a couple of discussions about this on the Angular github page , but other than saying this has been resolved, or pointing to an issue where there where ts files in node_modules - it was not helpful.

We're using Windows 10 here.

EDIT: the tsconfig files are (there are two):

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

The other (src/tsconfig.app.json):

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

These were both created by ng new .

Oh dear, I forgot to answer this question! It was answered in the Angular github a long time ago.

In Angular 5 you need to add --preserve-symlinks to both ng build and ng serve .

In Angular 6 you can no longer do that, and instead you need to add

 "preserveSymlinks": true,

to angular.json , you put it under architect/build/options of your project.

Verify that you are running at least node 6.9.x and npm 3.xx by running node -v and npm -v in a terminal/console window. Older versions produce errors, but newer versions are fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM