-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Node App with ESBuild + JS Library "Cannot find module". #18985
Comments
I had a similar error My project has a custom executor that generates/updates index barrel files on each build, when I disable this executor the error goes away, so it looks to be related to executors. |
Sorry, but I am new to nx and builds, so I am not sure what the "best" way to build the project is. I was learning how NX works and picked the defaults and struggled to get it to run and learned why it isn't working and wanted to let the team know. I may be able to help make a PR with a little direction.
test-workspace % tree -h dist
[ 96] dist
└── [ 96] apps
└── [ 256] test-app
├── [ 96] apps
│ └── [ 96] test-app
│ └── [ 128] src
│ ├── [1.6K] main.js
│ └── [ 879] main.js.map
├── [1.4K] main.js
├── [2.9K] main.js.map
├── [ 22K] package-lock.json
├── [ 141] package.json
└── [ 96] test-lib <------------------------ I don't think the library should be in the app.
└── [ 160] src
├── [1.1K] index.js
├── [ 207] index.js.map
└── [ 128] lib
├── [1.1K] test-lib.js
└── [ 279] test-lib.js.map
9 directories, 10 files
test-workspace % tree -h dist
[ 128] dist
├── [ 96] apps
│ └── [ 256] test-app
│ ├── [ 96] apps
│ │ └── [ 96] test-app
│ │ └── [ 128] src
│ │ ├── [1.6K] main.js
│ │ └── [ 879] main.js.map
│ ├── [1.4K] main.js
│ ├── [2.9K] main.js.map
│ ├── [ 22K] package-lock.json
│ ├── [ 141] package.json
│ └── [ 96] test-lib
│ └── [ 160] src
│ ├── [1.1K] index.js
│ ├── [ 207] index.js.map
│ └── [ 128] lib
│ ├── [1.1K] test-lib.js
│ └── [ 279] test-lib.js.map
└── [ 192] test-lib <--------------------- In my project it would be in libs/ but this works and shows the issue/workaround.
├── [ 230] README.md
├── [1.1K] index.cjs
├── [ 224] package-lock.json
└── [ 126] package.json
10 directories, 14 files |
I was able to fix my issue by getting How to switch the executor to ts-node:
@chmoder |
Thanks for the suggestions! Using the .env with prefer ts node didn't change the nx serve result. Here is the build section from "build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/test-lib",
"main": "test-lib/src/index.ts",
"tsConfig": "test-lib/tsconfig.lib.json",
"assets": ["test-lib/*.md"],
"generatePackageJson": true,
"format": ["cjs"]
}
} It is using And here is the build phase of test-app`. "build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"platform": "node",
"outputPath": "dist/apps/test-app",
"format": ["cjs"],
"bundle": false,
"main": "apps/test-app/src/main.ts",
"tsConfig": "apps/test-app/tsconfig.app.json",
"assets": ["apps/test-app/src/assets"],
"generatePackageJson": true,
"esbuildOptions": {
"sourcemap": true,
"outExtension": {
".js": ".js"
}
}
}, Source: |
@chmoder - Your issue looks to be different than mine. With a couple minor changes to the project structure I was able to get the project to build and run. Updated source: |
I see the changes you made, and it looks like it works but it is a little tricky. If you do
If you do |
I reported it in swc-project/swc-node#729, not sure if this should be fixed on their side or |
Thank you - I confirmed the issue was introduced with the addition of a default |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
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. |
Current Behavior
When I create a brand new project with a node app and library. Then import the library into the app and run :serve , it errors with cannot find module.
Expected Behavior
It builds affected libs and has them available for the app.
GitHub Repo
No response
Steps to Reproduce
Nx Report
Failure Logs
Package Manager Version
No response
Operating System
Additional Information
Work Arounds:
The text was updated successfully, but these errors were encountered: