#Modules not resolved (peer dependency issue?)

1 messages · Page 1 of 1 (latest)

crisp solar
#
PS C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server> bun run start
$ nest start
ERROR in ../../node_modules/@nestjs/core/nest-application.js 19:107-150
Module not found: Error: Can't resolve '@nestjs/websockets/socket-module' in 'C:\Users\unkno\Documents\RaidRequestHubMonorepo\node_modules\@nestjs\core'
 @ ../../node_modules/@nestjs/core/index.js 26:21-50
 @ ./src/main.ts 3:15-38

ERROR in ../../node_modules/@nestjs/core/nest-application.js 20:124-177
Module not found: Error: Can't resolve '@nestjs/microservices/microservices-module' in 'C:\Users\unkno\Documents\RaidRequestHubMonorepo\node_modules\@nestjs\core'
 @ ../../node_modules/@nestjs/core/index.js 26:21-50
 @ ./src/main.ts 3:15-38

ERROR in ../../node_modules/@nestjs/mapped-types/dist/type-helpers.utils.js 80:27-63
Module not found: Error: Can't resolve 'class-transformer/storage' in 'C:\Users\unkno\Documents\RaidRequestHubMonorepo\node_modules\@nestjs\mapped-types\dist'
 @ ../../node_modules/@nestjs/mapped-types/dist/index.js 23:27-58
 @ ../../node_modules/@nestjs/mapped-types/index.js 6:9-26
 @ ../../node_modules/@nestjs/swagger/dist/type-helpers/intersection-type.helper.js 4:23-54
 @ ../../node_modules/@nestjs/swagger/dist/type-helpers/index.js 17:13-50
 @ ../../node_modules/@nestjs/swagger/dist/index.js 22:13-38
 @ ../../node_modules/@nestjs/swagger/index.js 6:9-26
 @ ./src/main.ts 5:18-44

I am not using any of these packages in my app. When I installed them, I got 22 errors from modules not being resolved that were required in those 3 modules.

violet tiger
#

Are you using Bun? Although the Bun devs have pronounced that Nest will run in Bun, it seems it doesn't and Nest isn't claiming to have Bun compatibility either. So, you'll need to use Node.

crisp solar
violet tiger
#

Why?

crisp solar
# violet tiger Why?

Why what? It uses node because we aren't confident in moving onto a new runtime yet, however we have decided to try the bun package manager. The same error occurs using pnpm and I have used nest with bun package manager in the past successfully

violet tiger
#

Hmm.. 🤔

Can you please run your application with pnpm run and also install everything with pnpm (deleting node_modules) and then show the error you run into?

In general, Nest hasn't yet considered Bun a working option yet (despite the Bun folks saying Bun supports Nest). So. I need to see what happens in a "normal" environment to help. 🤷🏻‍♂️

crisp solar
#

Sure

violet tiger
#

Also, correct me if I am wrong, but in your OP, you have bun run start as the command used. Right?

crisp solar
#

Yes, thats correct, but it should run in node runtime unless I do bun --bun run start

#

(And accordingly I get a different error message when I do --bun)

violet tiger
#

Do you have shebangs in your files to force node?

#

Otherwise, you are running your code in Bun.

crisp solar
#

tsc has a shebang and nest cli has too

violet tiger
#

Ok. Got it.

#

I've not used Nest CLI for running my apps for a long while now. LOL! 😄

crisp solar
#

Yep, just double checked the source to be sure

violet tiger
#

I've also gotten from using TSC too. I use SWC. Blindingly fast. 🙂

#

I only type check at commit and trust VS Code's TS server for the rough checking.

crisp solar
#

I usually use swc but I needed to generate declaration files for one of my packages so I reverted back for now

#

I think I have misconfigured something with pnpm/tsconfig so I'll take another few mins

pnpm run start

> [email protected] start C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server
> nest start

webpack 5.90.1 compiled successfully in 10182 ms

C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server\dist\main.js:625
module.exports = require("api-types");
                 ^
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\unkno\Documents\RaidRequestHubMonorepo\packages\api-types\dist\index.js from C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server\dist\main.js not supported.
index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\Users\unkno\Documents\RaidRequestHubMonorepo\packages\api-types\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Object.__decorate (C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server\dist\main.js:625:18)
    at __webpack_require__ (C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server\dist\main.js:1662:42)
    at Object.<anonymous> (C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server\dist\main.js:493:21)
    at __webpack_require__ (C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server\dist\main.js:1662:42)
    at Object.<anonymous> (C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server\dist\main.js:374:28)
 ELIFECYCLE  Command failed with exit code 1.
violet tiger
#

What does your tsconfig.json look like?

crisp solar
#

I had specified it to compile to a module but it needed to be commonjs

viscid geode
#

Just was about to say, node shows at xyz in stacktraces, while the traces from the first post have @ xyz instead. Not sure what runtime that is, but it's not a clean node IMO.

violet tiger
#

And node development on Windows.... raises the hair on the back of my neck... LOL!" 😄

crisp solar
viscid geode
# crisp solar This error has been in the server before https://discord.com/channels/5206228127...

Yeah, sorry, I don't have a solution for you. Just noticed the difference in format of the stacktrace, suggesting the runtime is not really node.

It could be the issue, or one of many.

I tend to blame workspaces / monorepos, since those are the most common culprits with build issues from what I see around this server (not using them myself).

It could be helpful to figure out whether build works okay, e.g. split the commands to nest build and node dist/main to reduce the surface where the issue might be.

crisp solar
#

Ok, that was painful. The nest build succeeds but the node dist/main fails

PS C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server> pnpm run build   

> [email protected] build C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server
> nest build

webpack 5.90.1 compiled successfully in 9937 ms
PS C:\Users\unkno\Documents\RaidRequestHubMonorepo\apps\server> node dist/main.js
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [NestFactory] Starting Nest application...
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [InstanceLoader] PrismaModule dependencies initialized +55ms
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [InstanceLoader] JwtModule dependencies initialized +29ms
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [InstanceLoader] ConfigHostModule dependencies initialized +3ms
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [InstanceLoader] ConfigModule dependencies initialized +2ms
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [InstanceLoader] ClanModule dependencies initialized +6ms
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [InstanceLoader] MembersModule dependencies initialized +1ms
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [InstanceLoader] JwtModule dependencies initialized +0ms
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [InstanceLoader] UsersModule dependencies initialized +2ms
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 10804  - 02/04/2024, 17:47:51     LOG [InstanceLoader] AuthModule dependencies initialized +1ms
[Nest] 10804  - 02/04/2024, 17:47:51   ERROR [PackageLoader] The "class-transformer" package is missing. Please, make sure to install this library ($ npm install class-transformer) to take advantage of ValidationPipe.
#

I'll try install that package now

#

And it works

#

I'll commit that and try using bun again because I fixed about 20 configuration issues there

violet tiger
#

👍🏻

crisp solar
#

bun start succeeded

#

I have a theory that if I delete node_modules folders and reinstall it will not work

#

Yes. I will see if this is a bug or if modules are resolved differently with bun