question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tslib not found in node server production build

See original GitHub 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 (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
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
    at Function.Module._load (internal/modules/cjs/loader.js:690:27)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    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: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Users\\vinca\\Desktop\\main.js' ]
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

21reactions
hertzgcommented, 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

18reactions
vincasltcommented, Mar 9, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find module 'tslib' while dockerizing an Adonis app v5
Run the following command to create a production build. ... build folder to your production server, install the dependencies and run node ......
Read more >
tslib - npm
tslib. This is a runtime library for TypeScript that contains all of the TypeScript helper functions. This library is primarily used by the ......
Read more >
This syntax requires an imported helper but module 'tslib ...
To solve the error "This syntax requires an imported helper but module 'tslib' cannot be found", install tslib by running npm install -D...
Read more >
TypeScript for Node.js - Sentry Documentation
First, make sure that tslib is listed as the dependency in your package.json file. Once that's done, add two entries in compilerOptions section...
Read more >
TypeScript: JavaScript With Syntax For Types.
TypeScript is a strongly typed programming language that builds on ... which runs anywhere JavaScript runs: In a browser, on Node.js or Deno...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found