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

bug: remix vitePlugin module not found while running remix as vite plugin #21820

Closed
izznatsir opened this issue Jan 6, 2024 · 4 comments
Closed
Labels
bug Something isn't working correctly node compat

Comments

@izznatsir
Copy link

Version: Deno 1.39.2

{
  "compilerOptions": {
    "allowJs": true,
    "jsx": "react-jsx",
    "lib": ["DOM", "DOM.Iterable", "ES2022"],
    "strict": true
  },
  "imports": {
    "~/": "./app/"
  },
  "unstable": ["bare-node-builtins", "byonm", "sloppy-imports"]
}

I use the official unstable-vite template with Deno byonm mode as configured above. When executing deno task dev I saw below error:

failed to load config from /home/izznatsir/codes/local/deno/remix-vite/vite.config.ts
error when starting dev server:
SyntaxError: The requested module 'file:///home/izznatsir/codes/local/deno/remix-vite/node_modules/@remix-run/dev/dist/index.js' does not provide an export named 'unstable_vitePlugin' at file:///home/izznatsir/codes/local/deno/remix-vite/vite.config.ts.timestamp-1704507445127-6a0837dd2ff8a.mjs:2:10
    at async loadConfigFromBundledFile (file:///home/izznatsir/codes/local/deno/remix-vite/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:68380:21)
    at async loadConfigFromFile (file:///home/izznatsir/codes/local/deno/remix-vite/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:68237:28)
    at async resolveConfig (file:///home/izznatsir/codes/local/deno/remix-vite/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:67838:28)
    at async _createServer (file:///home/izznatsir/codes/local/deno/remix-vite/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:60327:20)
    at async CAC.<anonymous> (file:///home/izznatsir/codes/local/deno/remix-vite/node_modules/vite/dist/node/cli.js:764:24)

But, executing vite.config.ts directly is working via deno run -A vite.config.ts.

@kt3k kt3k added bug Something isn't working correctly node compat labels Jan 8, 2024
@kt3k
Copy link
Member

kt3k commented Jan 8, 2024

@dsherret Do you have any clue on this?

@marvinhagemeister
Copy link
Contributor

Intercepting what vite is doing it seems like the config file is transpiled to ESM:

import { unstable_vitePlugin as remix } from "file:///Users/marvinh/dev/test/my-remix-app/node_modules/@remix-run/dev/dist/index.js";
import { defineConfig } from "file:///Users/marvinh/dev/test/my-remix-app/node_modules/vite/dist/node/index.js";
import tsconfigPaths from "file:///Users/marvinh/dev/test/my-remix-app/node_modules/vite-tsconfig-paths/dist/index.mjs";
var vite_config_default = defineConfig({
  plugins: [remix(), tsconfigPaths()]
});
export {
  vite_config_default as default
};

But because the first import is a file:// import instead of npm: the CJS detection doesn't kick in. This works perfectly fine in node though.

Here is a minimal reproduction:

  1. Create a new folder and create a package.json file with these contents:
{
  "type": "module",
  "dependencies": {
    "@remix-run/dev": "^2.4.1"
  }
}
  1. Run npm i
  2. Create file foo.js these contents:
import * as remix from "@remix-run/dev";
console.log(remix);
  1. Run deno run -A --unstable-bare-node-builtins --unstable-byonm --unstable-sloppy-imports main.js -> Error

This works perfectly fine in node. It looks like we're not checking if the file resides in a module directory and check package.json for the module type.

@izznatsir izznatsir changed the title bug: unstable_vitePlugin module not found while running remix as vite plugin bug: remix vitePlugin module not found while running remix as vite plugin Feb 20, 2024
@birkskyum
Copy link
Contributor

birkskyum commented May 11, 2024

this repro appear to work with deno 1.43.3:

repos/deno-kitchensink/viteplugin via 🅒 base 
➜ node main.js 
[Module: null prototype] {
  __esModule: true,
  cli: { run: [AsyncFunction: run] },
  cloudflareDevProxyVitePlugin: [Function: cloudflareDevProxyVitePlugin],
  default: {
    cli: { run: [AsyncFunction: run] },
    getDependenciesToBundle: [Function: getDependenciesToBundle],
    vitePlugin: [Function: vitePlugin],
    cloudflareDevProxyVitePlugin: [Function: cloudflareDevProxyVitePlugin]
  },
  getDependenciesToBundle: [Function: getDependenciesToBundle],
  vitePlugin: [Function: vitePlugin]
}

repos/deno-kitchensink/viteplugin via 🅒 base 
➜ deno run -A --unstable-bare-node-builtins --unstable-byonm --unstable-sloppy-imports main.js
Warning Sloppy imports are not recommended and have a negative impact on performance.
[Module: null prototype] {
  __esModule: true,
  cli: { run: [AsyncFunction: run] },
  cloudflareDevProxyVitePlugin: [Function: cloudflareDevProxyVitePlugin],
  default: {
    cli: { run: [AsyncFunction: run] },
    getDependenciesToBundle: [Function: getDependenciesToBundle],
    vitePlugin: [Function: vitePlugin],
    cloudflareDevProxyVitePlugin: [Function: cloudflareDevProxyVitePlugin]
  },
  getDependenciesToBundle: [Function: getDependenciesToBundle],
  vitePlugin: [Function: vitePlugin]
}

Also the unstable-vite template is now simply named remix, and tracked further in

@izznatsir
Copy link
Author

It works! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

No branches or pull requests

4 participants