main.ts is missing from de TypeScript compilation
Hello,
I just installed node and tried to use cli. I went with the guide:
`npm install -g @angular/cli
ng new my-project cd my-project ng serve`
aaaaaand.... nope:
ERROR in C:/Users/hpelitebook/Documents/github/angularjs/angular2/src/main.ts
Module build failed: Error: C:\Users\hpelitebook\Documents\github\angularjs\angular2\src\main.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (C:\Users\hpelitebook\Documents\github\angularjs\angular2\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:674:23)
at plugin.done.then (C:\Users\hpelitebook\Documents\github\angularjs\angular2\node_modules\@ngtools\webpack\src\loader.js:467:39)
at <anonymous>
ERROR in C:/Users/hpelitebook/Documents/github/angularjs/angular2/src/polyfills.ts
Module build failed: Error: C:\Users\hpelitebook\Documents\github\angularjs\angular2\src\polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (C:\Users\hpelitebook\Documents\github\angularjs\angular2\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:674:23)
at plugin.done.then (C:\Users\hpelitebook\Documents\github\angularjs\angular2\node_modules\@ngtools\webpack\src\loader.js:467:39)
at <anonymous>
This is my first time with it and i'm not sure where to look
Thank you!
I am experiencing the same issue. I had my angular project working at one point but a few days ago something must have changed because I get the same error as santiagoblas when running ng serve, even after creating a new app. Following are the results from running ng -v:
Angular CLI: 1.7.3
Node: 8.9.4
OS: win32 x64
Angular: 5.2.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.7.3
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0
I have tried uninstalling and reinstalling Node.js.
Using Windows Command Prompt instead of Git Bash solved the issue, though I would like to know why Git Bash is no longer working for me.
Same issue here, I tried to create a new angular project with cli on a vanilla windows 10 computer. Installed everything from scratch with newest version and got this exact same error when executing ng build/serve with GIT Bash.
Thank's a lot @aruwanip for the advice to use windows CMD it works well that way !
I am getting the same error after upgrading to angular 5.2.10 from 4.4.3 and angular/cli to 1.7.4 from 1.6.7. I am running "ng build --watch --extractCss --base-href /portal/ --e=local --deploy-url=/Content/portal/" and I see the following...
ERROR in ./src/main.ts
Module build failed: Error: C:\dev\portal\src\main.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via
the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (C:\dev\portal\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:674:23)
at plugin.done.then (C:\dev\portal\node_modules\@ngtools\webpack\src\loader.js:467:39)
at process._tickCallback (internal/process/next_tick.js:109:7)
ERROR in ./src/polyfills.ts
Module build failed: Error: C:\dev\portal\src\polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (C:\dev\portal\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:674:23)
at plugin.done.then (C:\dev\portal\node_modules\@ngtools\webpack\src\loader.js:467:39)
Having the same issue:
> yarn build
yarn run v1.6.0
$ ng build
Date: 2018-05-22T19:52:01.735Z
Hash: 7a9bf0b1a9416b4e7f92
Time: 5862ms
chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered]
chunk {main} main.bundle.js, main.bundle.js.map (main) 929 bytes [initial] [rendered]
chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 886 bytes [initial] [rendered]
chunk {styles} styles.bundle.js, styles.bundle.js.map (styles) 261 kB [initial] [rendered]
ERROR in ./src/main.ts
Module build failed: Error: /Users/keegomyneego/Documents/Projects/roshub_web_app/src/main.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (/Users/keegomyneego/Documents/Projects/roshub_web_app/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:662:23)
at plugin.done.then (/Users/keegomyneego/Documents/Projects/roshub_web_app/node_modules/@ngtools/webpack/src/loader.js:467:39)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
@ multi ./src/main.ts
ERROR in ./src/polyfills.ts
Module build failed: Error: /Users/keegomyneego/Documents/Projects/roshub_web_app/src/polyfills.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (/Users/keegomyneego/Documents/Projects/roshub_web_app/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:662:23)
at plugin.done.then (/Users/keegomyneego/Documents/Projects/roshub_web_app/node_modules/@ngtools/webpack/src/loader.js:467:39)
at <anonymous>
@ multi ./src/polyfills.ts
error Command failed with exit code 1.
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"allowJs": true,
"noImplicitAny": false,
"noUnusedLocals": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strictNullChecks": true,
"baseUrl": "src",
"paths": {
"$assets/*": ["assets/*"],
"$environment": ["environments/environment"],
"$library/*": ["library/*"],
"~core/*": ["app/core/*"],
"~shared/*": ["app/shared/*"],
"~account/*": ["app/features/account/*"],
"~device/*": ["app/features/device/*"],
"~login/*": ["app/features/login/*"],
"~settings/*": ["app/features/settings/*"],
"~view/*": ["app/features/view/*"]
},
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
tsconfig.app.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015"
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
"files": [
"./scripts/extend-rxjs.ts"
]
}
.angular-cli.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "roshub_web_app"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "rh",
"styles": [
"sass/styles-app-loading.scss",
"sass/styles.scss"
],
"stylePreprocessorOptions": {
"includePaths": [
"../node_modules"
]
},
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.dev.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "scss",
"component": {
}
}
}
Update: Removing the "files" key from tsconfig.app.json fixed this issue for me. I believe "files" is auto-populated by ts if it's not specified, otherwise it exclusively uses the specified files (as mentioned in the tsconfig docs), which makes sense why it couldn't find a bunch of stuff.
I did just recently do an upgrade of certain Angular packages, but this may be unrelated. I'm also the only non-Windows user to have this issue so far.
@keego That is correct; for additional details please see here: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
I'm having the same issue with a newly-generated project using angular-cli version 6.0.3. At first, the project worked fine. After I added some files, I ran "ng serve" and it worked ok. Then I ran "ng build" and it failed. Now "ng serve" is not working either.
Both git bash and windows cmd fail.
UPDATE (confusing): Moving the entire project folder to another path solved my issue. Not sure whether it's a matter of permissions or long paths, but yeah now it works. I'll dig deeper into the permission thing and update the comment
Got this problem as well and got it working by moving to a shorter absolute path (rather than one relative to a symlink).
Here are run down with actual names changed to protect the guilty.
To me they demonstrate the problem isn't git console; It's DOS Symbolic Links created using mklink, (I guess that long paths would also be an issue though I didn't test them.)
Using;
- Windows Git bash console;
- Angular CLI: 1.7.4
- Node: 8.11.1
- OS: win32 x64
- Angular: 5.2.11
I did:
- cd ~/Repos/Bitbucket/myownname/myproject/
- Repos is symlink for d:/Repo
- ng new my-angular-project
- cd my-angular-project
- ng serve --open
- FAIL!!
- ng build
- FAIL!!
- mv my-angular-project/ /d/
- ng serve --open
- WORKS :-) !!!!
- Will rush through this a bit now; your probably getting board.
-
Created another project on /d/newproj and tested it worked; It did.
-
Moved it to my /d/Repos/newproj and went to it and it still worked.
-
Then vie symlink using ~/Repos/newproj and it Failed; so symlinks are bad
-
As home (~) has a bit of path length too it I tested this with the symlink on /c/ and it failed again
-
Git Bash MSYS symlinks are of course DOS
mklinkso tested it in DOS console through the link, and not through the link, and got the same result; symlinks are bad -
Just to be even more pedantic I tested it using cygwin symlinks which are not created using DOS mklink and guess what; IT WORK!!
So once again DOS proves the prophetic nature of it's own acronym. Bill Gates was truly a visionary oracle when he choose that name :-)
I had the same issue, here the problem was also me using a junction When starting from the actual path, it worked!
@igghera Thank you very much. Shortening the path solved my issue. Before my path was like: "C/user/my document/javascript/angular/project/proj-name" and got build errors. Then I changed to "C/Angular/proj-name" and it compiled and ran successfully.
It's my first time trying out Angular. You can imagine the frustration. Now I can continue with my lessons.
I also ran into this problem when using a DOS symbolic link. When I changed to the physical path of the directory, it built without error.
I fought with this issue for 2 weeks. Turned out to be the symbolic link issue. Moving my project to a real directory and it solved the issue for me.
I thought this sym link thing doesn't apply to me since I never created one. Later on I realized that the path I am using is ~/My Documents. The error went away when I used the path ~/Documents Should have never put my code within documents!
dont use symlinks, I open dir in VSCode from symlink and got same error (path is with symlink not the real dir), when I open it in target dir (the parh was real) it works, doesnt need any changes maybe hardlinks would be ok because it keeps true path
Not allowing Win symlinks in the path is really the answer, thanks! But I still fell that this could be worked somewhere... well, anyway, workaround ok!
@AlanCarlyle
Got this problem as well and got it working by moving to a shorter absolute path (rather than one relative to a symlink).
you deserve a big praise, thanks so much for this, was struggling for around 2 days where for all my colleagues our project works fine and for me it never built... turns out I was the reason because I always create symlinks to shorten the path... will be more careful with that in the future.
really thank you for finding this.
Same issue with D:\dev\path\to\folder
For reference if someone want to reproduce, I were using: mklink /J D:\dev C:\dev.
When using C:\dev\path\to\folder, it works fine.
This is still happening with the newest version of CLI?
Yes, still still happens with the latest cli. I just tried it today, because I opened my project after two month and had forget about this problem. Starting the ng commands (serve, build, etc.) from a absolute path works but if you are on a symlinked path, you will get an error. Because almost exclusively windows users get this problem, I think that it could be related to the different treatment of symlinks between Linux and Windows. Both "mklink" on windows cmd and "winln" on gitbash do not do the exactly same as "ln" in linux. And windows also treat symlinks in a slightly different way then linux do. But that this could be the reason of this problem is just a theory, because I have not enough background knowledge to say if this theory is correct..
Editing angular.json to add following attribute under the node "projects/{yourprojectname}/architect/build/options" should help: "preserveSymlinks": true