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

Issue with unstable_vitePlugin #161

Closed
hauptrolle opened this issue Nov 1, 2023 · 11 comments
Closed

Issue with unstable_vitePlugin #161

hauptrolle opened this issue Nov 1, 2023 · 11 comments

Comments

@hauptrolle
Copy link

hauptrolle commented Nov 1, 2023

Describe the bug

When using the new unstable_vitePlugin the dev server and build failes with the following error:

10:54:31 AM [vite] Error when evaluating SSR module /app/lib/i18n/i18next.server.ts: failed to import "remix-i18next"

export * from "./client";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at cjsLoader (node:internal/modules/esm/translators:345:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:294:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)

Steps to Reproduce the Bug or Issue

Us the new unstable_vitePlugin

Expected behavior

It does not throw an error.

@DavoCg
Copy link

DavoCg commented Nov 1, 2023

Hi @hauptrolle, I'm facing the same issue, I don't know Vite very well but it seems that using :

export default defineConfig({
  plugins: [remix(), tsconfigPaths()],
  ssr: {
    noExternal: ["remix-i18next"],
  },
});

makes this specific error you are mentioning disappear but introduces another error :

TypeError: headers.get is not a function
    at Module.getClientLocales (/Users/davo/dev/dials/node_modules/remix-i18next/browser/lib/get-client-locales.js:7:34)

I'll keep an eye on this issue to see if someone comes with a good fix.

edit: Last error seems to be known and related to : remix-run/remix#7819

@xHomu
Copy link
Contributor

xHomu commented Nov 1, 2023

As a temporary fix, try

import { RemixI18Next } from "node_modules/remix-i18next/browser/server.js"; and etc if this is a blocker for your vite migration.

@brandonpittman
Copy link

I'm seeing another issue with remix-i18n where Vite chokes on accept-language-parser and its use of module.exports syntax.

10:51:44 AM [vite] Error when evaluating SSR module /node_modules/accept-language-parser/index.js?v=caa3510c:
ReferenceError: module is not defined
    at /node_modules/accept-language-parser/index.js?v=caa3510c:73:1
    at instantiateModule (/node_modules/vite/dist/node/chunks/dep-6e2fe41e.js:50317:15)

@xHomu
Copy link
Contributor

xHomu commented Nov 7, 2023

I was recommended this Vite plugin, see if this solves it for you https://github.com/cyco130/vite-plugin-cjs-interop

@brandonpittman
Copy link

I solved the accept-language-parser by inlining the pick function into remix-i18n.

@brandonpittman
Copy link

Now I'm seeing this:

TypeError: headers.get is not a function
    at Module.getClientLocales (/node_modules/remix-i18next/browser/lib/get-client-locales.js:7:34)

@grinkus-adapt
Copy link

Now I'm seeing this:

TypeError: headers.get is not a function
    at Module.getClientLocales (/node_modules/remix-i18next/browser/lib/get-client-locales.js:7:34)

Seems like what's discussed in remix-run/remix#7819

@djhi
Copy link

djhi commented Nov 18, 2023

I don't have this issue anymore after upgrading remix to 2.3.0 and vite to 5.0.0.

Still using this configuration:

export default defineConfig({
  plugins: [remix(), tsconfigPaths()],
  ssr: {
    noExternal: ["remix-i18next"],
  },
});

@pimjansen
Copy link

pimjansen commented Dec 11, 2023

TypeError: headers.get is not a function
    at Module.getClientLocales (/node_modules/remix

This seems resolved in the 2.4.0 pre-release of remix/dev however it seems that the Server script returns an error

TypeError: __vite_ssr_import_2__.Response is not a constructor
    at onShellReady (/home/pim/projects/onderwijscatalogus/frontend/app/entry.server.tsx:59:13)
    at finishedTask (/home/pim/projects/onderwijscatalogus/frontend/node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom-server.node.development.js:6513:7)
    at retryTask (/home/pim/projects/onderwijscatalogus/frontend/node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom-server.node.development.js:6598:5)
    at performWork (/home/pim/projects/onderwijscatalogus/frontend/node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom-server.node.development.js:6642:7)
    at Immediate._onImmediate (/home/pim/projects/onderwijscatalogus/frontend/node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom-server.node.development.js:6969:12)
    at process.processImmediate (node:internal/timers:476:21)
TypeError: __vite_ssr_import_2__.Response is not a constructor
    at onShellReady (/home/pim/projects/onderwijscatalogus/frontend/app/entry.server.tsx:59:13)
    at finishedTask (/home/pim/projects/onderwijscatalogus/frontend/node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom-server.node.development.js:6513:7)
    at retryTask (/home/pim/projects/onderwijscatalogus/frontend/node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom-server.node.development.js:6598:5)
    at performWork (/home/pim/projects/onderwijscatalogus/frontend/node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom-server.node.development.js:6642:7)
    at Immediate._onImmediate (/home/pim/projects/onderwijscatalogus/frontend/node_modules/.pnpm/[email protected][email protected]/node_modules/react-dom/cjs/react-dom-server.node.development.js:6969:12)
    at process.processImmediate (node:internal/timers:476:21)

I see that the Response that is imported does not exist. So without it it runs fine

@aniforprez
Copy link

As of writing this, the issue is not presenting itself with remix 2.4.0. Seems like it's been fixed and the solution is to upgrade remix.

@sbaechler
Copy link

It still requires the noExternal config to run with Remix 2.5.

export default defineConfig({
  plugins: [remix(), tsconfigPaths()],
  ssr: {
    noExternal: ["remix-i18next"],
  },
});

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

10 participants