RE: Liferay 7.1 Angular npmRunBuild - TypeError: Cannot read property 'mai

Amos Fong, modified 6 Years ago. New Member Posts: 11 Join Date: 2/26/19 Recent Posts
Hey, I am new to angular and also liferay. I am attempting to integrate an angular project into liferay 7.1 using the liferay-npm-bundler.

I have managed to resolve the hundred or so previous errors so the module is now at a stage where it tries to bundle the 190 dependencies.

I am now receiving this error, I have googled it but cannot find anything on it at all.

Any help much appreciated.
​​​​​​​

> Task :downloadNode SKIPPED
> Task :modules:angular-npm-portlet:downloadNode SKIPPED
> Task :modules:angular-npm-portlet:expandJSCompileDependencies UP-TO-DATE
> Task :modules:angular-npm-portlet:npmInstall UP-TO-DATE

> Task :modules:angular-npm-portlet:npmRunBuild

> angular-npm-portlet@1.0.0 build C:\Users\User\Documents\process-portal\com-company-Project\modules\angular-npm-portlet
> tsc && liferay-npm-bundler

Bundling 190 dependencies...
TypeError: Cannot read property 'main' of undefined
    at loadAsDirectorySync (C:\Users\User\Documents\process-portal\com-company-Project\modules\angular-npm-portlet\node_modules\resolve\lib\sync.js:123:21)
    at loadNodeModulesSync (C:\Users\User\Documents\process-portal\com-company-Project\modules\angular-npm-portlet\node_modules\resolve\lib\sync.js:150:21)
    at Function.module.exports [as sync] (C:\Users\User\Documents\process-portal\com-company-Project\modules\angular-npm-portlet\node_modules\resolve\lib\sync.js:52:17)
    at configRequire (C:\Users\User\Documents\process-portal\com-company-Project\modules\angular-npm-portlet\node_modules\liferay-npm-bundler\lib\config.js:97:37)
    at C:\Users\User\Documents\process-portal\com-company-Project\modules\angular-npm-portlet\node_modules\liferay-npm-bundler\lib\config.js:241:22
    at Array.map (<anonymous>)
    at instantiatePlugins (C:\Users\User\Documents\process-portal\com-company-Project\modules\angular-npm-portlet\node_modules\liferay-npm-bundler\lib\config.js:233:21)
    at Object.getPlugins (C:\Users\User\Documents\process-portal\com-company-Project\modules\angular-npm-portlet\node_modules\liferay-npm-bundler\lib\config.js:224:9)
    at C:\Users\User\Documents\process-portal\com-company-Project\modules\angular-npm-portlet\node_modules\liferay-npm-bundler\lib\index.js:308:48
    at new Promise (<anonymous>)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! angular-npm-portlet@1.0.0 build: `tsc && liferay-npm-bundler`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the angular-npm-portlet@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\User\AppData\Roaming\npm-cache\_logs\2019-04-09T15_51_10_748Z-debug.log

> Task :modules:angular-npm-portlet:npmRunBuild FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':modules:angular-npm-portlet:npmRunBuild'.
> Process 'command 'cmd'' finished with non-zero exit value 1
Jacek Borowiec, modified 6 Years ago. New Member Post: 1 Join Date: 5/16/15 Recent Posts
We faced exactly the same problem, but we found that this must be OS dependent. 
On the OSX 10.13.6 and Debian v.9 compilation works.
On CentOS 7 and Ubuntu 10 we get almost identical error:

[[b]INFO[/b]] Bundling 18 dependencies...

[[b]INFO[/b]] TypeError: Cannot read property 'main' of undefined

[[b]INFO[/b]]     at loadAsDirectorySync (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/resolve/lib/sync.js:123:20)

[[b]INFO[/b]]     at loadNodeModulesSync (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/resolve/lib/sync.js:150:21)

[[b]INFO[/b]]     at Function.module.exports [as sync] (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/resolve/lib/sync.js:52:17)

[[b]INFO[/b]]     at configRequire (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/liferay-npm-bundler/lib/config/internal/util.js:33:37)

[[b]INFO[/b]]     at /home/jacekb/src/angular/my-npm-angular-portlet/node_modules/liferay-npm-bundler/lib/config/internal/bundler.js:104:46

[[b]INFO[/b]]     at Array.map (<anonymous>)

[[b]INFO[/b]]     at instantiatePlugins (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/liferay-npm-bundler/lib/config/internal/bundler.js:96:21)

[[b]INFO[/b]]     at Object.getPlugins (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/liferay-npm-bundler/lib/config/internal/bundler.js:79:9)

[[b]INFO[/b]]     at /home/jacekb/src/angular/my-npm-angular-portlet/node_modules/liferay-npm-bundler/lib/index.js:267:55

[[b]INFO[/b]]     at <anonymous>

[[b]ERROR[/b]] npm ERR! code ELIFECYCLE

[[b]ERROR[/b]] npm ERR! errno 1

[[b]ERROR[/b]] npm ERR! my-npm-angular-portlet@1.0.0 build: `tsc &amp;&amp; liferay-npm-bundler`

[[b]ERROR[/b]] npm ERR! Exit status 1

[[b]ERROR[/b]] npm ERR! 

[[b]ERROR[/b]] npm ERR! Failed at the my-npm-angular-portlet@1.0.0 build script.

[[b]ERROR[/b]] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
​​​​​​​</anonymous></anonymous>
mitch hancock, modified 6 Years ago. New Member Posts: 11 Join Date: 2/26/19 Recent Posts
Jacek BorowiecWe faced exactly the same problem, but we found that this must be OS dependent. 
On the OSX 10.13.6 and Debian v.9 compilation works.
On CentOS 7 and Ubuntu 10 we get almost identical error:

[[b]INFO[/b]] Bundling 18 dependencies...

[[b]INFO[/b]] TypeError: Cannot read property 'main' of undefined

[[b]INFO[/b]]     at loadAsDirectorySync (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/resolve/lib/sync.js:123:20)

[[b]INFO[/b]]     at loadNodeModulesSync (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/resolve/lib/sync.js:150:21)

[[b]INFO[/b]]     at Function.module.exports [as sync] (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/resolve/lib/sync.js:52:17)

[[b]INFO[/b]]     at configRequire (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/liferay-npm-bundler/lib/config/internal/util.js:33:37)

[[b]INFO[/b]]     at /home/jacekb/src/angular/my-npm-angular-portlet/node_modules/liferay-npm-bundler/lib/config/internal/bundler.js:104:46

[[b]INFO[/b]]     at Array.map (<anonymous>)

[[b]INFO[/b]]     at instantiatePlugins (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/liferay-npm-bundler/lib/config/internal/bundler.js:96:21)

[[b]INFO[/b]]     at Object.getPlugins (/home/jacekb/src/angular/my-npm-angular-portlet/node_modules/liferay-npm-bundler/lib/config/internal/bundler.js:79:9)

[[b]INFO[/b]]     at /home/jacekb/src/angular/my-npm-angular-portlet/node_modules/liferay-npm-bundler/lib/index.js:267:55

[[b]INFO[/b]]     at <anonymous>

[[b]ERROR[/b]] npm ERR! code ELIFECYCLE

[[b]ERROR[/b]] npm ERR! errno 1

[[b]ERROR[/b]] npm ERR! my-npm-angular-portlet@1.0.0 build: `tsc &amp;&amp; liferay-npm-bundler`

[[b]ERROR[/b]] npm ERR! Exit status 1

[[b]ERROR[/b]] npm ERR! 

[[b]ERROR[/b]] npm ERR! Failed at the my-npm-angular-portlet@1.0.0 build script.

[[b]ERROR[/b]] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
​​​​​​​</anonymous></anonymous>


Yes this is exactly the same error pretty much. I have Windows 10 Pro. Thanks for getting in touch. Not quite sure where to go from this
thumbnail
Ivan Zaera, modified 6 Years ago. Regular Member Posts: 119 Join Date: 10/1/13 Recent Posts
Apparently the bundler is failing when trying to instantiate a plugin. This is the source code that is failing:

https://github.com/liferay/liferay-npm-build-tools/blob/7d01c884866c9dd4bcd70d2cd15dc2e9b1fa855f/packages/liferay-npm-bundler/src/config/internal/bundler.js#L89

Can you see if there's something wrong in your .npmbundlerrc file? Otherwise I would advise to create an issue in https://github.com/liferay/liferay-npm-build-tools/issues and upload a zipped sample project to be able to reproduce it.

Thanks.
mitch hancock, modified 6 Years ago. New Member Posts: 11 Join Date: 2/26/19 Recent Posts
Thanks for the reply Ivan.

My .npmbundlerrc file is empty json such as in the example found in the below link.

https://github.com/liferay/liferay-blade-samples/blob/7.1/gradle/apps/npm/angular-npm-portlet/.npmbundlerrc

This compiles for the example angular project found in the link and also compiles for me locally when I run that module with my local instance of liferay 7.1

So that suggests to me that it is a problem with my module set up some how breaking the bundling component. 

I can go ahead and upload the code into an issue if that is what you suggest?
mitch hancock, modified 6 Years ago. New Member Posts: 11 Join Date: 2/26/19 Recent Posts
I ran a npm audit fix on the module.

During this parts of the package.json file were updated to newer versions, I am guessing that the key difference is the liferay-npm-bundler got updated from 2.0.0 to 2.7.1

After this upgrade the error has gone away and the files are bundled so this issue can be closed.

Thanks for the comments emoticon
thumbnail
Ivan Zaera, modified 6 Years ago. Regular Member Posts: 119 Join Date: 10/1/13 Recent Posts
Good to hear that.

However, 2.7.1 is a canary release, as you can see in the versions tab of https://www.npmjs.com/package/liferay-npm-bundler

I'm not saying that you can't use it because we are already using it too, but keep in mind that the latest stable is 2.6.2, in case you see any strange behaviour.
mitch hancock, modified 6 Years ago. New Member Posts: 11 Join Date: 2/26/19 Recent Posts
Ivan ZaeraGood to hear that.

However, 2.7.1 is a canary release, as you can see in the versions tab of https://www.npmjs.com/package/liferay-npm-bundler

I'm not saying that you can't use it because we are already using it too, but keep in mind that the latest stable is 2.6.2, in case you see any strange behaviour.

Thanks Ivan,

I have since tried version 2.6.2 however it fails to bundle in that version.
So something changed in version 2.7.1 to make it work for me.

​​​​​​​Thanks