Reputation: 313
I have a Nrwl Nx repo with different apps (angular, nodejs with express) and shared libs inside.
The repo was created with the nx cli
and I want to build for production one of the express
apps.
nx build:production myexpressapp
The bundle I get is very nice and runs if I run it (with pm2) from where it was built (dist
folder).
However, if I get it to production, the node modules are missing and the app does not start.
If I copy the node_modules folder above the one with the built dist it works as well.
But I would very much like either of:
I tried using "vendorChunk":true
in my production build options but nothing changes.
Any thoughts?
Upvotes: 11
Views: 11666
Reputation: 793
If you're missing the node_modules
folder entirely, you need to add the generatePackageJson
option to your project.json
Like so:
"targets": {
"build": {
"executor": "@nrwl/webpack:webpack",
"options": {
"outputPath": "...",
"main": "...",
"tsConfig": "...",
"assets": [...],
"generatePackageJson": true,
"target": "node",
"compiler": "tsc"
},
...
Upvotes: 0
Reputation: 2222
Looking at angular.json
(or workspace.json
), if your builder
is @nrwl/node:build
, under options
, set externalDependencies
to none
, like so:
{
"projects": {
"api": {
"architect": {
"build": {
"builder": "@nrwl/node:build",
"options": {
"externalDependencies": "none"
...
You may experience errors like:
ERROR in ...
Module not found: Error: Can't resolve 'some-modules' in ...
Just keep installing what its complaining about, until it stops.
Reference: Nrwl Nx Node Builder
Upvotes: 11