-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Unable to build NestJS based project #4803
Comments
I have a similar issue, when running packages using require-optional it's failing to load the dependency Cannot find package "mongodb-extjson" from "/node_modules/mongodb/lib/core/utils.js"
|
Same. Trying to migrate existent project to use bun as runtime. As i understand running For dev server tried:
it failed with such error: I noticed that it is cuz of prom-client. Related to #4708 bun ./src/main.ts
8 | }, $;
9 |
10 | class NotImplementedError extends Error {
11 | code;
12 |
13 | constructor(feature, issue) {
^
NotImplementedError: PerformanceObserver is not yet implemented in Bun.
code: "ERR_NOT_IMPLEMENTED" trying to build app also provides lots of errors: bun build ./src/main.ts --target=bun ─╯
error: Could not resolve: "@nestjs/websockets/socket-module". Maybe you need to "bun install"?
const { SocketModule } = (0, optional_require_1.optionalRequire)('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
^
/Users/${projectDir}/node_modules/@nestjs/core/nest-application.js:19:116 1093
error: Could not resolve: "@nestjs/websockets/socket-module". Maybe you need to "bun install"?
const { SocketModule } = (0, optional_require_1.optionalRequire)('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
^
/Users/${projectDir}/node_modules/@nestjs/microservices/nest-microservice.js:12:116 769
error: Could not resolve: "@grpc/grpc-js". Maybe you need to "bun install"?
grpcPackage = (0, load_package_util_1.loadPackage)('@grpc/grpc-js', ClientGrpcProxy.name, () => require('@grpc/grpc-js'));
^
/Users/${projectDir}/node_modules/@nestjs/microservices/client/client-grpc.js:28:113 1471
error: Could not resolve: "@grpc/proto-loader". Maybe you need to "bun install"?
? require('@grpc/proto-loader')
^
/Users/${projectDir}/@nestjs/microservices/client/client-grpc.js:30:23 1677 |
+1 for this issue |
Literally same thing on my side, same issues which |
I made a PR to Solution: we may need to ask bun to change the error message to match the one from node. I searched through bun source code and I think this is the one: bun/src/bun.js/ResolveMessage.zig Line 55 in 3510916
|
Same Problem on my side. When trying to build this repo with the following command I have the same errors. bun build --target bun --outdir ./out src/main.ts This are the errors shown in the console: error: Could not resolve: "@nestjs/microservices". Maybe you need to "bun install"?
const { NestMicroservice } = (0, load_package_util_1.loadPackage)('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
^
/home/ansgar/repositories/nestjs-api/node_modules/@nestjs/core/nest-factory.js:57:129 2923
error: Could not resolve: "@nestjs/websockets/socket-module". Maybe you need to "bun install"?
const { SocketModule } = (0, optional_require_1.optionalRequire)('@nestjs/websockets/socket-module', () => require('@nestjs/websockets/socket-module'));
^
/home/ansgar/repositories/nestjs-api/node_modules/@nestjs/core/nest-application.js:19:116 1093
error: Could not resolve: "@nestjs/microservices/microservices-module". Maybe you need to "bun install"?
const { MicroservicesModule } = (0, optional_require_1.optionalRequire)('@nestjs/microservices/microservices-module', () => require('@nestjs/microservices/microservices-module'));
^
/home/ansgar/repositories/nestjs-api/node_modules/@nestjs/core/nest-application.js:20:133 1263
error: Could not resolve: "@nestjs/microservices". Maybe you need to "bun install"?
const { NestMicroservice } = (0, load_package_util_1.loadPackage)('@nestjs/microservices', 'NestFactory', () => require('@nestjs/microservices'));
^
/home/ansgar/repositories/nestjs-api/node_modules/@nestjs/core/nest-application.js:123:129 5792
error: Could not resolve: "mock-aws-s3". Maybe you need to "bun install"?
const AWSMock = require('mock-aws-s3');
^
/home/ansgar/repositories/nestjs-api/node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:43:29 1141
error: Could not resolve: "aws-sdk". Maybe you need to "bun install"?
const AWS = require('aws-sdk');
^
/home/ansgar/repositories/nestjs-api/node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:76:23 2020
error: Could not resolve: "nock". Maybe you need to "bun install"?
const nock = require('nock');
^
/home/ansgar/repositories/nestjs-api/node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js:112:24 2898
error: Could not resolve: "class-transformer/storage". Maybe you need to "bun install"?
classTransformer = require('class-transformer/storage');
^
/home/ansgar/repositories/nestjs-api/node_modules/@nestjs/mapped-types/dist/type-helpers.utils.js:71:36 3118 |
same here: with bun build there are still issues. I have still to use nest build and node. So +1 for fixing this issue |
Still occurs in the latest version of bun |
works for me if i install the deps with npm.
|
What's up guys. I managed to make it work with some flags. We must add "-e" for each library that gives an error in the log. bun build --target=bun -e @nestjs/websockets/socket-module -e ts-morph -e amqplib -e amqp-connection-manager -e nats -e @apollo/subgraph -e mqtt -e @nestjs/sequelize -e @mikro-orm/core -e @nestjs/typeorm -e @nestjs/mongoose -e class-transformer/storage -e kafkajs -e @nestjs/microservices -e class-transformer -e class-validator --minify src/main.ts --outdir out I still can't use it in a large project as it depends on the |
As a guess this behavior may have to do with how The script uses a simple heuristic to determine whether to mark a dependency as external: if dependency A is marked as The script assumes import Bun from 'bun';
const entrypoint = 'main.ts';
type PackageJson = {
readonly peerDependencies?: Record<string, unknown>;
readonly peerDependenciesMeta?: Record<string, { readonly optional?: boolean }>;
};
const externals: string[] = [];
for await (const path of new Bun.Glob('./node_modules/**/package.json').scan('.')) {
const { peerDependencies, peerDependenciesMeta } = (await Bun.file(path).json()) as PackageJson;
if (peerDependencies && peerDependenciesMeta) {
for (const dependency of Object.keys(peerDependencies)) {
if (peerDependenciesMeta[dependency]?.optional) {
const exists = await Bun.file(`node_modules/${dependency}/package.json`).exists();
if (!exists) {
externals.push(dependency);
}
}
}
}
}
await Bun.$`bun build --target=bun -e ${{ raw: externals.join(' -e ') }} --compile ${entrypoint}`; (caveat emptor) This will obviously lead to a runtime error if the dependency is supposed to be there and isn't either shipped with the build artifact or provided at runtime so please vet the result and use with caution! I don't know if this fix is comprehensive for the class of issues, but fwiw I tried on a medium sized project that had ~8 dependencies that blew up the build and all met the criteria above (it obv will not help with |
About the sharp support in build it can be achieved if using wasm version, but for now bun not support specify the cpu architecture in the install. #9636 |
@Jarred-Sumner similar to my previous comment tonight about production usage, this is also blocking (for full bun switchover that is). I have our servers running in docker using dependencies installed by bun but the main.js is run with Fine with running it with Node and installing with Bun for the time being though, thats already much faster than before. |
A successful solution for packaging Nestjs |
any updates? |
@tungv we will update the error message in Bun to use single quotes instead of double quotes |
What version of Bun is running?
1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983
What platform is your computer?
Linux 6.4.13-200.fc38.x86_64 x86_64 unknown
What steps can reproduce the bug?
Create a hello world app in NestJS then try to compile it?
What is the expected behavior?
Application compiles.
What do you see instead?
Additional information
It's still possible to run it using
bun run
(however, start time is quite long).Related to #1641
The text was updated successfully, but these errors were encountered: