-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module build failed: TypeError: Cannot read property 'newLine' of undefined #3781
Comments
Can you provide repro steps please? |
I've solved it on my side by adding the required AotPlugin item to my plugins
check out the usage for more information on the options |
Where webpack configuration is placed inside bootstrapped project? |
I've located the root source of that error at https://github.com/angular/angular-cli/blob/master/packages/%40ngtools/webpack/src/loader.ts#L186 The instanceof check fails. Therefore, the The instanceof fails because the export of plugin.ts is executed two times in the compiled JavaScript vendor source, leading to similar AotPlugin ctors, but not strictly equal. If I remove the instanceof check, everything works as expected. It may happen in some specific setups. In my case, build logic and the application aren't in the same npm modules. {
test: /\.ts$/,
loader: require.resolve('@ngtools/webpack')
} In the application module, Webpack does a require() of the path given by require.resolve(). Since it's not the same module, node executes the export again, giving a new, non equal, AotPlugin ctor. There are some ways to fix the issue on my side, like deporting @ngtools/webpack in the application module. On the library side, removing the instanceof check in favor of a more duck-typed approach is also a possibility. |
Hello! |
@phamlehoaian In most cases, this is simply because you forgot to add the AotPlugin. |
@toverux Can you please tell me how to add AotPlugin? I did not forget! I have no experience about this! Please help me! Thank you. |
This doesn't seem to be a problem with the As far as I can tell, @hozefam and @phamlehoaian were having problems with My bet is that this is dependency problem. Are you absolutely sure you followed https://github.com/angular/angular-cli#updating-angular-cli when upgrading? I'm testing a new project right now and don't get this. But I know this can happen with outdated dependencies, and that happens if you don't follow the upgrade guide. |
@filipesilva I faced this problem in fresh new installed nodejs and angular-cli. So I think that it is not related with upgrading. BTW, in project folder, I noticed that the file webpack.config.js is not existed. Is it right? |
@phamlehoaian yes that is right, you shouldn't have Can you tell me exactly what you did so I can reproduce the error? The exact commands please, and if you changed any files in the project. |
@filipesilva Okay, I will remove all nodejs as this guide http://stackoverflow.com/questions/38602808/uninstall-node-js-windows-10, then I will install new, keep all commands and send to you. Please wait. |
@phamlehoaian no need to do all that, these steps are enough: https://github.com/angular/angular-cli#updating-angular-cli |
@filipesilva It's so strange! After I uninstall all things and start new install to this command |
@phamlehoaian sometimes these things happen and there are dependency problems. I'm glad it's working correctly for you now :D |
Had to update my npm and angular cli. After that is done. Delete your project folder, clone it back again. Run npm install. And things should work. |
@deepakkadarivel new clone idea worked for now |
|
Thanks @hnrchrdl, that worked for me. |
thanks @hnrchrdl |
go through this, this might help. https://github.com/angular/angular-cli#updating-angular-cli |
shorthand of @hnrchrdl's solution, all in one:
|
@mmathys your command got truncated in github. This is what I received in email notification: rm -rf node_modules && npm cache clean && npm uninstall --save angular-cli && npm uninstall -g angular-cli && npm i --save @angular/cli && npm i -g @angular/cli && npm i && npm start |
@mmathys I needed 'sudo' for the -g installs/uninstallls, otherwise, just what I needed :) |
In my case, this error was because I updated to beta.32 and I didn't noticed that the node_modules folder was not completely removed. |
… is not an NgModule" http://stackoverflow.com/questions/41431682/appmodule-is-not-an-ngmodule-error-despite-setting-typescript-to-version-2-0 angular/angular-cli#4594 -- ts version 2.1.5, not 2.1.6 Earlier error: angular/angular-cli#3781
it need delete node_module |
Guys you have to completely delete npm packages, in Windows it is in your
user profile. This problem caused the npm update on my machine. When I
cleaned all the packages previously downloaded in global, it works like a
charm.
…On Jun 12, 2017 18:37, "Jon Gunter" ***@***.***> wrote:
I've spent 16 hours working on this problem with a angular-cli project.
I've tried every solution listed here, with nothing that gets it working. I
wish I could provide a repro, but doesn't seem to happen with any other CLI
project on my machine.
I feel pretty frustrated because I thought the Angular team had ironed out
most of the issues with the CLI. But after this, I'm still not convinced
it's a stable platform yet. The project in question had been left alone for
3 months, then cloning it onto my computer and reinstalling the npm
dependencies causes the "newline" error message when I try to ng serve it.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3781 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFA0wSfzdWN2apG1G0dfoMr1bsZAZgF0ks5sDWkzgaJpZM4LXj2l>
.
|
Thanks for your responses. I tried the following on my Mac and PC with no solution:
Furthermore, this project in question seems to be working on one of my colleague's Macs, which is strange because it doesn't work on my Mac, which is the exact same model with the exact same MacOS version. I We spent months putting this project together for a demo. I think I might be at my wits end with Angular right now. The fact that there's no useful error message or stack trace here is particularly infuriating for me. |
I've just discovered that if I check in Maybe @filipesilva has an idea? |
This seems to be a dependency issue, as copying the same Check out my repro...this is broken on my machine, and I hope other people can reproduce this: |
I have the same issue: ng -v @angular/cli: 1.0.3 tsc -v Version 2.3.4 Errors: ERROR in ./src/main.ts ERROR in ./src/polyfills.ts I try each manual of packages reinstalling/upgrading but nothing can helps me. |
@filipesilva , this issue should be reopened. I have a reproducible test case posted above (if it's not reproducing the error for you, please let me know). Even if this is deemed as case of "operator error", there should be a more helpful error message to let the user know what's going on. |
I had this bug today because i was i had angular/cli version 1.1.2 installed, i resolved it by installing @angular/[email protected] Steps include: Hope that helps. |
If anyone was wondering, I have resolved this issue by Still, I think this shouldn't be necessary...the error should tell me roughly what I need to fix. |
Thanks a lot. As @jongunter said I create new app and merge package.js and it's working now. |
I had the same error. I had to go through @MartinFreire 's steps and (don't ask me why) delete package.-ock.json . |
I looked into this during the weekend and have to say that @toverux explanation in #3781 (comment) is spot on. For projects using |
@filipesilva Thank you. |
Currently, having multiple @ngtools/webpack installed yields a cryptic error in typescript: ``` ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined ``` This happens because a plugin is found, but it isn't an instance of the right class. This makes the loader assume it's being ran without a plugin (just transpiling TS). Then it tries to load a missing tsconfig and the error above is shown. This PR introduced better errors for both the wrong plugin instance and missing tsconfig. ``` ERROR in ./src/main.ts Module build failed: Error: AotPlugin was detected but it was an instance of the wrong class. This likely means you have several @ngtools/webpack packages installed.You can check this with `npm ls @ngtools/webpack`, and then remove the extra copies. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:371:19) @ multi ./src/main.ts ``` ``` ERROR in ./src/main.ts Module build failed: Error: @ngtools/webpack is being used as a loader but no `tsConfigPath` option norAotPlugin was detected. You must provide at least one of these. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:442:19) @ multi ./src/main.ts ``` See angular#3781 (comment) and angular#3781 (comment) for context.
Currently, having multiple @ngtools/webpack installed yields a cryptic error in typescript: ``` ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined ``` This happens because a plugin is found, but it isn't an instance of the right class. This makes the loader assume it's being ran without a plugin (just transpiling TS). Then it tries to load a missing tsconfig and the error above is shown. This PR introduced better errors for both the wrong plugin instance and missing tsconfig. ``` ERROR in ./src/main.ts Module build failed: Error: AotPlugin was detected but it was an instance of the wrong class. This likely means you have several @ngtools/webpack packages installed.You can check this with `npm ls @ngtools/webpack`, and then remove the extra copies. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:371:19) @ multi ./src/main.ts ``` ``` ERROR in ./src/main.ts Module build failed: Error: @ngtools/webpack is being used as a loader but no `tsConfigPath` option norAotPlugin was detected. You must provide at least one of these. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:442:19) @ multi ./src/main.ts ``` See angular#3781 (comment) and angular#3781 (comment) for context.
Currently, having multiple @ngtools/webpack installed yields a cryptic error in typescript: ``` ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined ``` This happens because a plugin is found, but it isn't an instance of the right class. This makes the loader assume it's being ran without a plugin (just transpiling TS). Then it tries to load a missing tsconfig and the error above is shown. This PR introduced better errors for both the wrong plugin instance and missing tsconfig. ``` ERROR in ./src/main.ts Module build failed: Error: AotPlugin was detected but it was an instance of the wrong class. This likely means you have several @ngtools/webpack packages installed.You can check this with `npm ls @ngtools/webpack`, and then remove the extra copies. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:371:19) @ multi ./src/main.ts ``` ``` ERROR in ./src/main.ts Module build failed: Error: @ngtools/webpack is being used as a loader but no `tsConfigPath` option norAotPlugin was detected. You must provide at least one of these. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:442:19) @ multi ./src/main.ts ``` See #3781 (comment) and #3781 (comment) for context.
Currently, having multiple @ngtools/webpack installed yields a cryptic error in typescript: ``` ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined ``` This happens because a plugin is found, but it isn't an instance of the right class. This makes the loader assume it's being ran without a plugin (just transpiling TS). Then it tries to load a missing tsconfig and the error above is shown. This PR introduced better errors for both the wrong plugin instance and missing tsconfig. ``` ERROR in ./src/main.ts Module build failed: Error: AotPlugin was detected but it was an instance of the wrong class. This likely means you have several @ngtools/webpack packages installed.You can check this with `npm ls @ngtools/webpack`, and then remove the extra copies. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:371:19) @ multi ./src/main.ts ``` ``` ERROR in ./src/main.ts Module build failed: Error: @ngtools/webpack is being used as a loader but no `tsConfigPath` option norAotPlugin was detected. You must provide at least one of these. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:442:19) @ multi ./src/main.ts ``` See #3781 (comment) and #3781 (comment) for context.
Currently, having multiple @ngtools/webpack installed yields a cryptic error in typescript: ``` ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined ``` This happens because a plugin is found, but it isn't an instance of the right class. This makes the loader assume it's being ran without a plugin (just transpiling TS). Then it tries to load a missing tsconfig and the error above is shown. This PR introduced better errors for both the wrong plugin instance and missing tsconfig. ``` ERROR in ./src/main.ts Module build failed: Error: AotPlugin was detected but it was an instance of the wrong class. This likely means you have several @ngtools/webpack packages installed.You can check this with `npm ls @ngtools/webpack`, and then remove the extra copies. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:371:19) @ multi ./src/main.ts ``` ``` ERROR in ./src/main.ts Module build failed: Error: @ngtools/webpack is being used as a loader but no `tsConfigPath` option norAotPlugin was detected. You must provide at least one of these. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:442:19) @ multi ./src/main.ts ``` See #3781 (comment) and #3781 (comment) for context.
Still receiving this error, despite having only one version of @ngtools/webpack installed.
|
OS : Windows with Angular 4 "@angular/cli": "1.2.1", I just removed the caret from above two dependencies and performed following steps, everything started working perfectly.
|
ERROR in ./src/main.ts ERROR in ./src/polyfills.ts I'm getting this when I run "ng serve".. Is this just a typescript error or more? |
OK, as many others have mentioned this is due to version mismatches with webpack or angular-cli, but never seems to be fixed by deleting the node_modules folder or re-installing / uninstalling packages manually. I FINALLY managed to get this working by deleting node_modules folder AND the package-lock.json file... Then running npm install seemed to fix this for me. |
If I remember correctly my fix to the issue went something like this..
rm -r npm_modules
sudo -i npm clear cache
sudo npm -g uninstall @angular/cli
perhaps "npm uninstall @angular/cli" locally if need be..
then install with npm again, I realised my problem was that somehow.. I
managed to have a local version
that was different that the global version and the older one was being
used..
check versions ng -v, etc..also I used npm3 not npm ;)
…On Wed, Jul 26, 2017 at 6:00 PM, Adam Tirella ***@***.***> wrote:
OK, as many others have mentioned this is due to version mismatches, but
never seems to be fixed by deleting the node_modules folder or
re-installing / uninstalling packages.
I FINALLY managed to get this working by deleting node_modules folder AND
the package-lock.json file... Then running npm install seemed to fix this
for me.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3781 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGDyiP0_rQVX4NhNTuK22b861u3DCFmmks5sR37AgaJpZM4LXj2l>
.
|
Currently, having multiple @ngtools/webpack installed yields a cryptic error in typescript: ``` ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined ``` This happens because a plugin is found, but it isn't an instance of the right class. This makes the loader assume it's being ran without a plugin (just transpiling TS). Then it tries to load a missing tsconfig and the error above is shown. This PR introduced better errors for both the wrong plugin instance and missing tsconfig. ``` ERROR in ./src/main.ts Module build failed: Error: AotPlugin was detected but it was an instance of the wrong class. This likely means you have several @ngtools/webpack packages installed.You can check this with `npm ls @ngtools/webpack`, and then remove the extra copies. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:371:19) @ multi ./src/main.ts ``` ``` ERROR in ./src/main.ts Module build failed: Error: @ngtools/webpack is being used as a loader but no `tsConfigPath` option norAotPlugin was detected. You must provide at least one of these. at Object.ngcLoader (D:\work\cli\packages\@ngtools\webpack\src\loader.ts:442:19) @ multi ./src/main.ts ``` See angular#3781 (comment) and angular#3781 (comment) for context.
Hey, guys, my problem was solved due @macandcheese comment -
the @filipesilva rightly explained the reason of issue -
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
ERROR in multi main
Module not found: Error: Can't resolve 'webpack-dev-server/client?http://localho
st:4200/' in 'D:\Hozefa\Ang\FirstApp\TestApp'
@ multi main
Anyone?
OS?
Windows 7
Versions.
angular-cli: 1.0.0-beta.24
node: 4.4.6
os: win32 x64
@angular/common: 2.4.1
@angular/compiler: 2.4.1
@angular/core: 2.4.1
@angular/forms: 2.4.1
@angular/http: 2.4.1
@angular/platform-browser: 2.4.1
@angular/platform-browser-dynamic: 2.4.1
@angular/router: 3.4.1
@angular/compiler-cli: 2.4.1
The log given by the failure.
ERROR in multi main
Module not found: Error: Can't resolve 'webpack-dev-server/client?http://localho
st:4200/' in 'D:\Hozefa\Ang\FirstApp\TestApp'
@ multi main
ERROR in ./src/main.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
at Object.getNewLineCharacter (D:\Hozefa\Ang\FirstApp\TestApp\node_modules\t
ypescript\lib\typescript.js:8062:20)
at Object.createCompilerHost (D:\Hozefa\Ang\FirstApp\TestApp\node_modules\ty
pescript\lib\typescript.js:44978:26)
at Object.ngcLoader (D:\Hozefa\Ang\FirstApp\TestApp\node_modules@ngtools\we
bpack\src\loader.js:171:31)
@ multi main
The text was updated successfully, but these errors were encountered: