Skip to content
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

nestjs prod build fail due to externalDependencies #1174

Closed
4 tasks done
xmlking opened this issue Mar 14, 2019 · 7 comments · Fixed by #1212
Closed
4 tasks done

nestjs prod build fail due to externalDependencies #1174

xmlking opened this issue Mar 14, 2019 · 7 comments · Fixed by #1212

Comments

@xmlking
Copy link
Contributor

xmlking commented Mar 14, 2019

Please make sure you have read the submission guidelines before posting an issue

Prerequisites

Please answer the following questions for yourself before submitting an issue.
YOU MAY DELETE THE PREREQUISITES SECTION.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed
  • I'm reporting the issue to the correct repository (not related to Angular, AngularCLI or any dependency)

Expected Behavior

sample project : https://github.com/xmlking/ngx-starter-kit

ng build api --prod should work without warnings and errors

Current Behavior

ng build api works but ng build api --prod throw following error

PS: if I remove "externalDependencies": "none" from angular.json api project, it works

WARNING in ./node_modules/ws/lib/validation.js
Module not found: Error: Can't resolve 'utf-8-validate' in '/Developer/Work/SPA/ngx-starter-kit/node_modules/ws/lib'
 @ ./node_modules/ws/lib/validation.js
 @ ./node_modules/ws/lib/sender.js
 @ ./node_modules/ws/index.js
 @ ./node_modules/engine.io/lib/server.js
 @ ./node_modules/engine.io/lib/engine.io.js
 @ ./node_modules/socket.io/lib/index.js
 @ ./apps/api/src/app/shared/eventbus.gateway.ts
 @ ./apps/api/src/app/shared/index.ts
 @ ./apps/api/src/app/user/user.module.ts
 @ ./apps/api/src/app/user/index.ts
 @ ./apps/api/src/app/app.module.ts
 @ ./apps/api/src/main.ts
 @ multi ./apps/api/src/main.ts

ERROR in ./node_modules/got/index.js
Module not found: Error: Can't resolve 'electron' in '/Developer/Work/SPA/ngx-starter-kit/node_modules/got'
 @ ./node_modules/got/index.js 75:29-48
 @ ./node_modules/openid-client/lib/helpers/http.js
 @ ./node_modules/openid-client/lib/issuer.js
 @ ./node_modules/openid-client/lib/index.js
 @ ./node_modules/kubernetes-client/lib/auth-providers/openid.js
 @ ./node_modules/kubernetes-client/lib/auth-providers sync ^\.\/.*\.js$
 @ ./node_modules/kubernetes-client/lib/backends/request.js
 @ ./node_modules/kubernetes-client/lib/swagger-client.js
 @ ./node_modules/kubernetes-client/lib/index.js
 @ ./apps/api/src/app/project/kubernetes/kubernetes.service.ts
 @ ./apps/api/src/app/project/project.module.ts
 @ ./apps/api/src/app/project/index.ts
 @ ./apps/api/src/app/app.module.ts
 @ ./apps/api/src/main.ts
 @ multi ./apps/api/src/main.ts

ERROR in ./node_modules/pg/lib/native/client.js
Module not found: Error: Can't resolve 'pg-native' in '/Developer/Work/SPA/ngx-starter-kit/node_modules/pg/lib/native'
 @ ./node_modules/pg/lib/native/client.js 9:13-33
 @ ./node_modules/pg/lib/native/index.js
 @ ./node_modules/pg/lib/index.js
 @ ./node_modules/typeorm/platform/PlatformTools.js
 @ ./node_modules/typeorm/entity-manager/MongoEntityManager.js
 @ ./node_modules/typeorm/index.js
 @ ./apps/api/src/app/auth/auth.service.ts
 @ ./apps/api/src/app/auth/index.ts
 @ ./apps/api/src/app/app.module.ts
 @ ./apps/api/src/main.ts
 @ multi ./apps/api/src/main.ts

ERROR in ./node_modules/engine.io/lib/server.js
Module not found: Error: Can't resolve 'uws' in '/Developer/Work/SPA/ngx-starter-kit/node_modules/engine.io/lib'
 @ ./node_modules/engine.io/lib/server.js 90:23-37
 @ ./node_modules/engine.io/lib/engine.io.js
 @ ./node_modules/socket.io/lib/index.js
 @ ./apps/api/src/app/shared/eventbus.gateway.ts
 @ ./apps/api/src/app/shared/index.ts
 @ ./apps/api/src/app/user/user.module.ts
 @ ./apps/api/src/app/user/index.ts
 @ ./apps/api/src/app/app.module.ts
 @ ./apps/api/src/main.ts
 @ multi ./apps/api/src/main.ts

ERROR in ./node_modules/sharp/build/Release/sharp.node 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
 @ ./node_modules/sharp/lib/utility.js 3:14-52
 @ ./node_modules/sharp/lib/index.js
 @ ./apps/api/src/app/user/profile/profile.service.ts
 @ ./apps/api/src/app/user/user.module.ts
 @ ./apps/api/src/app/user/index.ts
 @ ./apps/api/src/app/app.module.ts
 @ ./apps/api/src/main.ts
 @ multi ./apps/api/src/main.ts

Context

sample project : https://github.com/xmlking/ngx-starter-kit

Please provide any relevant information about your setup:

  • version of Nx used
  • version of Angular CLI used
  • angular.json configuration
  • version of Angular DevKit used
  • 3rd-party libraries and their versions
  • and most importantly - a use-case that fails

A minimal reproduce scenario using allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem.

Failure Logs

Please include any relevant log snippets or files here.

Other

Any other relevant information that will help us help you.

@xmlking
Copy link
Contributor Author

xmlking commented Mar 14, 2019

this could be reproduces with

npx create-nx-workspace myorg --preset="full-stack"
ng build api --prod

@ZenSoftware
Copy link

There seems to be issues with a bare-bones nx project using [email protected] as well. I submitted an issue in the nest repo here: nestjs/nest#1706

Minimum reproduction can be found here: Nx & [email protected] bug reproduction

@xmlking
Copy link
Contributor Author

xmlking commented Mar 17, 2019

may be nx provide noWebPack option (ng build api --noWebPack --prod) for node projects.
WebPack bundles has no real benefit for server-side apps and some times, not compatible well with some frameworks (e.g, typeorm migrations etc)

@ZenSoftware
Copy link

It would be nice if there was a no webpack option. I'm not sure if there is. The --prod flag is usually only used to indicate that we want to use the environments.prod.ts file during the compilation of server side Node apps.

@xmlking
Copy link
Contributor Author

xmlking commented Mar 20, 2019

looks like nx already support excluding some or all node modules from bundling externalDependencies: 'all' | 'none' | string[]; here

for my case "externalDependencies": "all" worked.

Still prefer nx offer option to exclude webpack for cases like this #1167

@FrozenPandaz
Copy link
Collaborator

Using externalDependencies: 'all' should work. We would like bundling to be the default in production for deploying a lighter docker image. Let's keep discussing in nestjs/nest#1706 because there is more information there.

We could provide a ts-node builder but it would lack some features like being unable to do fileReplacements and such.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants