Skip to content
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

Module not found: Can't resolve 'next/dist/shared/lib/router-context' #88

Open
robatronPrime opened this issue Feb 1, 2024 · 8 comments

Comments

@robatronPrime
Copy link

In [email protected] the router-context file has changed name to router-context.shared-runtime.

Changing the line at ./node_modules/next-translate-routes/react/withTranslateRoutes.js:38:0 from
var router_context_1 = require("next/dist/shared/lib/router-context");
to
var router_context_1 = require("next/dist/shared/lib/router-context.shared-runtime");
fixes the issue.

However, it would be cool if it new which version of next was being used and changed the import depending on the next version?

@artkondakov
Copy link

Got the same problem and yes, @robatronPrime solution is really working. I tried to use Webpack config to add alias

"next/dist/shared/lib/router-context$": path.join(
    __dirname,
    "..",
    "..",
    "node_modules",
    "next/dist/shared/lib/router-context.shared-runtime.js"
),

but it doesn't work...

@patrykmostowski
Copy link

patrykmostowski commented Feb 19, 2024

Provided a fix, your next version was set to latest, when checking the next version the plugin checked for a number, and omitted 'latest' string, setting ur Router Context path to old, resulting in this problem

If you need a quick solution for a cloud deployment like heroku or netlify just use yarn/pnpm/npm install [email protected], fixes the issue

@dsmiletzki
Copy link

In [email protected] the router-context file has changed name to router-context.shared-runtime.

Changing the line at ./node_modules/next-translate-routes/react/withTranslateRoutes.js:38:0 from var router_context_1 = require("next/dist/shared/lib/router-context"); to var router_context_1 = require("next/dist/shared/lib/router-context.shared-runtime"); fixes the issue.

However, it would be cool if it new which version of next was being used and changed the import depending on the next version?

Same problem for me.

@artkondakov
Copy link

Maybe anyone had successfully solved the problem for the next-translate-routes v10 with aliases?... I just can't understand why my solution isn't working

@patrykmostowski
Copy link

patrykmostowski commented Feb 21, 2024

i have written a temporary solution, especialy if you need a quick fix for a cloud deployment just add this script in root directory.

const fs = require('fs');
const path = require('path');

/**
 * @param {string} filePath - The path to the file.
 * @param {string} searchPattern - The RegExp pattern to search for.
 * @param {string} replaceString - The string to replace with.
 */
function replaceLineInFile(filePath, searchPattern, replaceString) {
  const fileContent = fs.readFileSync(filePath, 'utf8');

  const modifiedContent = fileContent.replace(searchPattern, replaceString);

  fs.writeFileSync(filePath, modifiedContent);
  console.log(`File updated: ${filePath}`);
}

const filePath = path.join(__dirname, 'node_modules', '/next-translate-routes/react/', 'withTranslateRoutes.js');
const searchPattern = /var router_context_1 = require\("next\/dist\/shared\/lib\/router-context"\);/g;
const replaceString = 'var router_context_1 = require("next/dist/shared/lib/router-context.shared-runtime");';
replaceLineInFile(filePath, searchPattern, replaceString);

from there, you just run it before build with node, and then everything should work as expected

@patrykmostowski
Copy link

Bumping the thread.
Would be nice if someone addressed this issue and went through PR's waiting to be merged. 👍🏻

@redveronika
Copy link

Have the same issue, bumping the thread.

@cvolant
Copy link
Collaborator

cvolant commented Mar 26, 2024

Hi! Sorry that it took so long, but I went through 3 intense months, and had to prioritize.
I just release 1.11.0-5, that basically drop support for old next version (<13.5.0), in order to fix this issue. I tried hard to maintain the support, as reflected in the version number, without success. I hope it is ok this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants