Nx: tslib not found in node server production build

Created on 8 Mar 2020  路  3Comments  路  Source: nrwl/nx

Prerequisites

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

  • [x] I am running the latest version
  • [x] I checked the documentation (nx.dev) and found no answer
  • [x] I checked to make sure that this issue has not already been filed
  • [x] 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' ]
}

Most helpful comment

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

All 3 comments

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

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

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

Was this page helpful?
0 / 5 - 0 ratings