toonvanstrijp / nestjs-i18n

The i18n module for nestjs.
https://nestjs-i18n.com
Other
626 stars 101 forks source link

Cannot find module 'typescript' #551

Closed Ferm0494 closed 10 months ago

Ferm0494 commented 10 months ago

Describe the bug

When building Docker Images, we exclude devDependencies such as typescript found in /utils/typescript.js, had to be included to production dependencies in order to make the tree flow

Reproduction

yarn install --production

System Info

code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/fernandorivas/Desktop/Personal/CORE/MAIN/node_modules/nestjs-i18n/dist/utils/typescript.js',
    '/Users/fernandorivas/Desktop/Personal/CORE/MAIN/node_modules/nestjs-i18n/dist/utils/index.js',
    '/Users/fernandorivas/Desktop/Personal/CORE/MAIN/node_modules/nestjs-i18n/dist/services/i18n.service.js',
    '/Users/fernandorivas/Desktop/Personal/CORE/MAIN/node_modules/nestjs-i18n/dist/i18n.module.js',
    '/Users/fernandorivas/Desktop/Personal/CORE/MAIN/node_modules/nestjs-i18n/dist/index.js',
    '/Users/fernandorivas/Desktop/Personal/CORE/MAIN/dist/apps/core/main.js'
  ]

Used Package Manager

yarn

Validations

d4ins commented 10 months ago

For some reason after the typescript compiles it adds to node_modules/nestjs-i18n/dist/utils/index.js this line:

__exportStar(require("./typescript"), exports);

Probably the solution is to add this:

"exclude": ["node_modules", "**/*.spec.ts", "src/utils/typescript.ts"]

to tsconfig.build.json.

For now, anyone who has this issue has two options:

Ferm0494 commented 10 months ago

Really hard to do option 2 in Docker, I've opted for option 1, working perfectly.

d4ins commented 10 months ago

You can always use https://www.npmjs.com/package/patch-package

therealwalim commented 10 months ago

You can add this file nestjs-i18n+10.3.1.patch to your patches directory with this content:

diff --git a/node_modules/nestjs-i18n/dist/utils/index.js b/node_modules/nestjs-i18n/dist/utils/index.js
index 13bca8b..d1d0300 100644
--- a/node_modules/nestjs-i18n/dist/utils/index.js
+++ b/node_modules/nestjs-i18n/dist/utils/index.js
@@ -18,6 +18,5 @@ __exportStar(require("./context"), exports);
 __exportStar(require("./file"), exports);
 __exportStar(require("./format"), exports);
 __exportStar(require("./merge"), exports);
-__exportStar(require("./typescript"), exports);
 __exportStar(require("./util"), exports);
 //# sourceMappingURL=index.js.map
\ No newline at end of file

And check about postinstall to apply the changes.

simbolmina commented 10 months ago

My lamda function (serverless fm and github actions) gave this error, and patch fixed it.

npm i patch-package

github action file

  - name: Apply Patches
    run: npx patch-package

I also have the same app deployed elsewhere there I install typescript as a global dependecy so it works as well.

nettags commented 10 months ago

This issue also breaks Heroku deployments because devDependencies are removed on production builds.

For me, reverting to version 10.2.6 works.

SimonPotier commented 10 months ago

Had the same issue, installed typescript as a regular dependency solved the problem. Looking forward a prettier solution in the future.

rubiin commented 10 months ago

Lets add this to docs

rubiin commented 10 months ago

I have added a section to the docs https://nestjs-i18n.com/faq/common#cannot-find-module-typescript . If there are any other viable solution , let me know so I can add them there as well

SvendDomdey commented 10 months ago

Thank you for maintaining this lib. Just a little comment from our perspective here:

We cannot use option 2 from the docs as our project is deployed automatically by a pipeline somewhere into the cloud (no access for us). We do not need typescript as a production dependency and do not want to add it "artificially" because of this issue. Therefore, we will stick to version 10.2.6 for the moment.

Would like to know the perspective of other consumers for sure.. :)

rubiin commented 10 months ago

I think something broke on the current version. I will have to write a test to see if I can roll this change back

rubiin commented 10 months ago

This seems to be fixed with the https://github.com/toonvanstrijp/nestjs-i18n/pull/565 . You can try the latest version