#SWC Error When Module is imported in another module.

10 messages · Page 1 of 1 (latest)

normal jay
#

Error: Cannot find module 'src/test2/test2.module'
Require stack:

  • C:\Users\exfled\Desktop\test-nest\test-nest-project\dist\test\test.module.js
  • C:\Users\exfled\Desktop\test-nest\test-nest-project\dist\app.module.js
  • C:\Users\exfled\Desktop\test-nest\test-nest-project\dist\main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\exfled\Desktop\test-nest\test-nest-project\dist\test\test.module.js:14:22)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)

It is newly generated project with everything latest and it has only this 2 TestModule and Test2Module. Test2Module is imported in TestModule. Also both are imported in App Module.

ocean sky
#

I believe, unless you have "paths" set up in your tsconfig.json, you need to use relative paths, otherwise src won't be resolved.

normal jay
#

Suggestions how can i do that ?

uneven folio
limber peak
#

I have this problem but am not using aliases

#

my imports do look like this "src/resource/services/resource.service" how would I express this in a path in swrc?

#

paths are normally for aliases right? things like :

"@/*": ["src/*"]

#

actually I responded my own question @normal jay I think you may want to add:

"paths": {
  "src/*": ["src/*"]
}

to your .swcrc file

ocean sky
#

@uneven folio

Or update both tsconfig and .swcrc files to support path aliases
Updating the (or even needing a) .swcrc file isn't necessary in a Nest app using the Nest CLI. It uses the info from tsconfig.json for paths, when the builder is SWC. 🙂

normal jay
#

This solutions doesn't work I get the same error the only thing that helps is if I change all the imports to be relative in TS which is not ideal becouse the project is big. ex: ../test2/test2.module