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

tslib not found in node server production build #2625

Closed
4 tasks done
vincaslt opened this issue Mar 8, 2020 · 9 comments
Closed
4 tasks done

tslib not found in node server production build #2625

vincaslt opened this issue Mar 8, 2020 · 9 comments
Labels

Comments

@vincaslt
Copy link

vincaslt commented Mar 8, 2020

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 (nx.dev) 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 React, Angular or any dependency)

Expected Behavior

I build a production build of my node app, which is generated from @nrwl/node, calling nx build api --prod. I copy the generated files onto my server (or just another directory) and start it with node main.js.

Current Behavior

The error I get when starting is:

> node main.js
internal/modules/cjs/loader.js:800
    throw err;
    ^

Error: Cannot find module 'tslib'
Require stack:
- C:\Users\vinca\Desktop\main.js
�[90m    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)�[39m
�[90m    at Function.Module._load (internal/modules/cjs/loader.js:690:27)�[39m
�[90m    at Module.require (internal/modules/cjs/loader.js:852:19)�[39m
�[90m    at require (internal/modules/cjs/helpers.js:74:18)�[39m
    at Object.<anonymous> (C:\Users\vinca\Desktop\main.js:91:18)
    at __webpack_require__ (C:\Users\vinca\Desktop\main.js:20:30)
    at Object.<anonymous> (C:\Users\vinca\Desktop\main.js:1086:17)
    at __webpack_require__ (C:\Users\vinca\Desktop\main.js:20:30)
    at Object.<anonymous> (C:\Users\vinca\Desktop\main.js:1076:18)
    at __webpack_require__ (C:\Users\vinca\Desktop\main.js:20:30) {
  code: �[32m'MODULE_NOT_FOUND'�[39m,
  requireStack: [ �[32m'C:\\Users\\vinca\\Desktop\\main.js'�[39m ]
}
@vincaslt
Copy link
Author

vincaslt commented Mar 8, 2020

I sense this is because api build does not include vendors. Is there a configuration option I'm missing?

@vincaslt
Copy link
Author

vincaslt commented Mar 9, 2020

I added this flag in production build config: "externalDependencies": "none"

@agrinko
Copy link

agrinko commented Jun 17, 2020

@vincaslt , thank you, it helped! I would never guess it...

@hertzg
Copy link

hertzg commented Mar 2, 2021

For people who are trying out nx and ended up here from google.

You probably have set "importHelpers": true (default config) in your tsconfig.base.json which will use tslib package when there's a need to emit helpers in generated code.

--importHelpers | boolean | false | Import emit helpers (e.g. __extends, __rest, etc..) from tslib

There are reasons when such behavior is Preferred but if you want to opt out of it you could set that flag to false.

References

@vanduc1102
Copy link

vanduc1102 commented Jul 17, 2021

Should we add the tslib to generated packageJson by default ?
When I add "importHelpers": false the build hangs up.

Maybe this could be temporary solutions:

1 -


COPY --from=builder /workdir/dist/apps/${SERVICE_NAME} /workdir
COPY --from=builder /workdir/yarn.lock /workdir/yarn.lock

RUN yarn install --production
RUN yarn add tslib@2.0.0

CMD ["node", "main.js"]

2 -
Adding import 'tslib'; into main.ts also help.

@y-chen
Copy link

y-chen commented Jun 1, 2022

I have the same error but when I set "importHelpers": false I get the same errors with different modules, like typeorm.

I can't really install missing packages after the build because the production server doesn't have internet access.

Is there a way to build in all the necessary dependencies?

@Kalanamith
Copy link

This issue still exists

@ankuragrwl
Copy link

I did the following and it worked for me:

In the nestjs App's project.json file, configure generatePackageJson : true inside the build configuration section.

Then add RUN npm --prefix api-gateway --omit=dev -f install to the Dockerfile

@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 Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants