You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ERROR in Cannot read property 'getSourceFile' of undefined #5329
Hi, I am trying to configure webpack in order to work with AOT, however I am getting this error. I tried with changing versions but without success, in some cases I even got more errors.
ERROR in Cannot read property 'getSourceFile' of undefined
ERROR in C:/Workspace/webpack-aot/public/javascripts/core/projects/main.aot.ts (3,34): Cannot find module './ngfactory/public/javascripts/core/projects/app.module.ngfactory'.)
ERROR in ./public/javascripts/core/projects/main.aot.ts
Module not found: Error: Can't resolve './ngfactory/public/javascripts/core/projects/app.module.ngfactory' in 'C:\Workspace\webpack-aot\public\javascripts\core\projects'
@ ./public/javascripts/core/projects/main.aot.ts 3:0-103
The error lies in node_modules@ngtools\webpack\src\compiler_host.js in function _resolve(path), when the operating system is Windows.
In some cases, this function calls to path.join, which returns a normalized path under the current OS, which does not correspond to the idea of _resolve function to replace backslashes with normal slashes.
Until a new version with this fix appears, you can replace manually that function with the code as follows:
_resolve(path) {
path = this._normalizePath(path);
if (path[0] == '.') {
return this._normalizePath(path_1.join(this.getCurrentDirectory(), path));
}
else if (path[0] == '/' || path.match(/^\w://)) {
return path;
}
else {
return this._normalizePath(path_1.join(this._basePath, path));
}
}
After this, the problem disappears.
Reacted by Michael Peiffer, Mitch Talmadge, drew moore, Ravindra, Brett Fernandes and Jonathan Lian
I have the same problem. After changing this method, the error persists:
ERROR in Cannot read property 'getSourceFile' of undefined
ERROR in /home/arlindo/git/vendedoronline/frontend/src/app/utils/hmac-http-client.ts (39,63): Cannot find name 'CryptoJS'.)
/home/arlindo/git/vendedoronline/frontend/src/app/utils/hmac-http-client.ts (41,63): Cannot find name 'CryptoJS'.)
/home/arlindo/git/vendedoronline/frontend/src/app/utils/hmac-http-client.ts (43,63): Cannot find name 'CryptoJS'.)
ERROR in /home/arlindo/git/vendedoronline/frontend/src/app/security/securityToken.ts (5,9): Cannot find name '_'.)
ERROR in /home/arlindo/git/vendedoronline/frontend/src/app/account/account.ts (12,13): Cannot find name '_'.)
ERROR in /home/arlindo/git/vendedoronline/frontend/src/app/empresa/empresa.ts (11,13): Cannot find name '_'.)
ERROR in /home/arlindo/git/vendedoronline/frontend/src/app/fabricante/fabricante.ts (10,13): Cannot find name '_'.)
ERROR in /home/arlindo/git/vendedoronline/frontend/src/app/linha/linha.ts (10,13): Cannot find name '_'.)
Thanks for sharing @tinchou! That fixed it for me. Was having the same problem on Windows 10....wasted more time than I care to admit on this issue. :-)
Yeah, that sucks. The problem is not knowing which one is the broken
component after a big update. I was lucky I was glancing over that repo's
issues a couple of hours before updating myself.
where is this webpack.config.js file everyone speaks of along with the aotPlugin settings? Does @angular/cli use it?
I've been trying to get a --prod and/or --aot build to work for months... seem to be in upgrade/dependency hell / along with not having any idea where the error lines
I'm not using the CLI, but webpack with @ngtools/webpack plugin. I think
you can "eject" your webpack configuration with the CLI if you need to use
this workaround.
Activity
Dobryvechir commentedon Mar 11, 2017
The error lies in node_modules@ngtools\webpack\src\compiler_host.js in function _resolve(path), when the operating system is Windows.
In some cases, this function calls to path.join, which returns a normalized path under the current OS, which does not correspond to the idea of _resolve function to replace backslashes with normal slashes.
Until a new version with this fix appears, you can replace manually that function with the code as follows:
_resolve(path) {
path = this._normalizePath(path);
if (path[0] == '.') {
return this._normalizePath(path_1.join(this.getCurrentDirectory(), path));
}
else if (path[0] == '/' || path.match(/^\w://)) {
return path;
}
else {
return this._normalizePath(path_1.join(this._basePath, path));
}
}
After this, the problem disappears.
PaybackMan commentedon Mar 16, 2017
horrible error message
maffelbaffel commentedon Mar 22, 2017
This error literally cost me 5 hours debugging. Replacing with
solved it for me thought.
@Dobryvechir's code was missing a backslash:
arlindonatal commentedon Mar 22, 2017
I have the same problem. After changing this method, the error persists:
ERROR in Cannot read property 'getSourceFile' of undefined
The references:
colltoaction commentedon Mar 25, 2017
I'm on Windows 10 using
@ngtools/webpack:1.3.0. I can confirm @maffelbaffel's fix works.You can paste this into your
webpack.config.jsand avoid touching thenode_modulesfolder, especially useful for automated deployment scenarios:DanWahlin commentedon Mar 26, 2017
Thanks for sharing @tinchou! That fixed it for me. Was having the same problem on Windows 10....wasted more time than I care to admit on this issue. :-)
colltoaction commentedon Mar 26, 2017
tavelli commentedon Apr 12, 2017
@tinchou can you share plugins context of your webpack config for this workaround?
colltoaction commentedon Apr 13, 2017
What do you mean? This?
tavelli commentedon Apr 13, 2017
@tinchou yea thanks, i had dumb mistake with var aotPlugin = new ngToolsWebpack.AotPlugin({ part defined after webpack config instead of before
hheexx commentedon Apr 13, 2017
@tinchou screw_ie8: true, is default. You don't need that.
bkdotcom commentedon Apr 14, 2017
where is this
webpack.config.jsfile everyone speaks of along with the aotPlugin settings?Does @angular/cli use it?
I've been trying to get a --prod and/or --aot build to work for months... seem to be in upgrade/dependency hell / along with not having any idea where the error lines
ng build --aotexpanding that:
colltoaction commentedon Apr 14, 2017
mariussl commentedon Apr 19, 2017
thx @tinchou for the workaround, works perfectly for me (win7x64)
rbarcelos commentedon Apr 24, 2017
Any ETA for when a final fix for this will be deployed? Thanks
hheexx commentedon Apr 25, 2017
Deployed in 1.3.1
mariussl commentedon Apr 26, 2017
thx @hheexx . bugfix confirmed.
filipesilva commentedon May 23, 2017
Fixed by #6063
uscbsitric commentedon Nov 3, 2017
I solved min by pressing Ctrl + C on the terminal to end the current npm start,
then ran the entire setup with a npm start.
This error occurred to me when I was switching branches.
angular-automatic-lock-bot commentedon Sep 7, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.