martinkr/next-export-i18n

Not compatible with PNPM

Opened this issue · 14 comments

I'm encountering this issue when switching from yarn to pnpm:

https://nextjs.org/docs/messages/module-not-found
wait  - compiling...
error - ./node_modules/.pnpm/registry.npmmirror.com+next-export-i18n@2.0.3_c0abbb53577d424fe320649841fdc7d4/node_modules/next-export-i18n/index.js:5:0
Module not found: Can't resolve './../../i18n/index.js'

By reading the source code, the issue is that next-export-i18n assumed it would always be located as <project_folder>/node_modules/next-export-i18n. This is no longer true with pnpm, as it utilized the hard link feature so next-export-18n would be in another location.

I'm still investigating pnpm whether there is solution to make certain package as an exception. No clue yet...

Hey!

Thank you for your contribution. Unfortunately, I never used pnpm. I need to investigate this as well...

Cheers!

Thanks for your reply.

One possible solution you can consider is to pass the config object during the initialization, comparing to current implementation this could eliminate the assumption of the file naming and location.

Thanks for your great project.

Hey!

Planning to implement this in the next release.
If you like, you can also raise a pull request :)

Cheers!

Great. Looking forward to that.

Hey, looks like the expectation of locale folder location makes it incompatible with the monorepo setup as well, where you have the i18 folder not in ./../../i18n/index.js, but in ./../../apps/consumer-app/i18n/.
The compat fix for pnpm would probably make this problem go away. As @hughlv noted, hardcoding the config path is probably a bit dangerous. Any chance you found a workaround?

@hughlv hey, im also experiencing that with pnpm
the solutions is you can patch package with pnpm patch https://pnpm.io/cli/patch and set
var I18N = require('./../../i18n/index.js'); path as you want.
for me i've had to add few extra "parent paths" ../

I also met this issue, :(

thanks to @mihamor , this is my solution, (bash history):

 1968  pnpm patch next-export-i18n@^2.1.0
 1969  subl /private/var/folders/zv/jzl76zs903z4wdj_fdskc92r0000gn/T/730a0dd5dbc8fa11edad43fd784b62dd
 1970  cd ./node_modules/.pnpm/next-export-i18n@2.1.0_pxeeag5fab3ngpbhgu2rjk6nzy_yucv4tfv7v7nrkw2uguegj6e7e/node_modules/next-export-i18n
 1971  cd ./../../../../../i18n
 1974  pnpm patch-commit /private/var/folders/zv/jzl76zs903z4wdj_fdskc92r0000gn/T/730a0dd5dbc8fa11edad43fd784b62dd

this is the final generated patch file:

diff --git a/index.js b/index.js
index 79f31c56e96382496d9ba42f7fa4da736ecfcb47..de12b2889ff1c8bc2480f818c51328b5b1b14109 100644
--- a/index.js
+++ b/index.js
@@ -2,7 +2,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
 
 var router = require('next/router');
 var React = require('react');
-var I18N = require('./../../i18n/index.js');
+var I18N = require('./../../../../../i18n/index.js');
 var Mustache = require('mustache');
 
 function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

and package.json

"pnpm": {
    "patchedDependencies": {
      "next-export-i18n@2.1.0": "patches/next-export-i18n@2.1.0.patch"
    }
  }

Any updates?

@martinkr we are using pnpm as well. This makes it impossible for us to work with this package, sad.

Hi @SalahAdDin,

I appreciate your interest in this package. Unfortunately, I don't use ppm in my projects. Hence, I need to gain practical experience with this package manager's concepts.

If you would consider adding Pnpm support, I would happily merge your PR for the next release.

Looking forward to your PR,

Martin

I also met this issue, :(

thanks to @mihamor , this is my solution, (bash history):

 1968  pnpm patch next-export-i18n@^2.1.0
 1969  subl /private/var/folders/zv/jzl76zs903z4wdj_fdskc92r0000gn/T/730a0dd5dbc8fa11edad43fd784b62dd
 1970  cd ./node_modules/.pnpm/next-export-i18n@2.1.0_pxeeag5fab3ngpbhgu2rjk6nzy_yucv4tfv7v7nrkw2uguegj6e7e/node_modules/next-export-i18n
 1971  cd ./../../../../../i18n
 1974  pnpm patch-commit /private/var/folders/zv/jzl76zs903z4wdj_fdskc92r0000gn/T/730a0dd5dbc8fa11edad43fd784b62dd

this is the final generated patch file:

diff --git a/index.js b/index.js
index 79f31c56e96382496d9ba42f7fa4da736ecfcb47..de12b2889ff1c8bc2480f818c51328b5b1b14109 100644
--- a/index.js
+++ b/index.js
@@ -2,7 +2,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
 
 var router = require('next/router');
 var React = require('react');
-var I18N = require('./../../i18n/index.js');
+var I18N = require('./../../../../../i18n/index.js');
 var Mustache = require('mustache');
 
 function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

and package.json

"pnpm": {
    "patchedDependencies": {
      "next-export-i18n@2.1.0": "patches/next-export-i18n@2.1.0.patch"
    }
  }

what about opening a MR?

@hughlv hey, im also experiencing that with pnpm the solutions is you can patch package with pnpm patch https://pnpm.io/cli/patch and set var I18N = require('./../../i18n/index.js'); path as you want. for me i've had to add few extra "parent paths" ../

it would be good then to update the package to use aliases...

Hi @SalahAdDin,

Would you consider providing a set of instruction of how to achieve pnpm compatibility? In the Code Snippet, we're referring specific version numbers, hence it would not be feasible to add this snippet directly to the codebase.

Thank you for your contribution!

Cheers!

Hi @SalahAdDin,

Would you consider providing a set of instructions on how to achieve pnpm compatibility? In the Code Snippet, we're referring to specific version numbers, hence it would not be feasible to add this snippet directly to the codebase.

Thank you for your contribution!

Cheers!

It was @JimmyLv who made the patch.