nitrojs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.build
MIT License
6.16k stars 507 forks source link

Dynamic Imports Aren't Compiled (JSX) #2760

Open ghost opened 1 month ago

ghost commented 1 month ago

Environment

$ node --version
v18.20.3
$ npm ls
+-- @esbuild/linux-x64@0.20.2 extraneous
+-- @parcel/watcher-linux-x64-glibc@2.4.1 extraneous
+-- @parcel/watcher-linux-x64-musl@2.4.1 extraneous
+-- @rollup/rollup-linux-x64-gnu@4.22.5 extraneous
+-- @rollup/rollup-linux-x64-musl@4.22.5 extraneous
+-- nitropack@2.9.7
`-- node-addon-api@7.1.1 extraneous

Reproduction

stackblitz.com/edit/node-ru2nde

Describe the bug

When programmatically generating a path for importing with await import(), Nitro does not compile the imported file correctly.

const { default: _App } = import("src/App.jsx"); // 👍 `src/App.jsx` converted to `js` and imported

const { default: _App } = import(path.resolve(process.cwd(), "src/App.jsx")); // 👎 `src/App.jsx` not compiled
const { default: _App } = import(`${'/home/projects/node-ru2nde/src/App.jsx'}`) // 👎 `src/App.jsx` not compiled

Additional context

No response

Logs

Unknown file extension ".jsx" for /home/projects/node-ru2nde/src/App.jsx

  at __node_internal_captureLargerStackTrace2 (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:101:5335)
  at new NodeError (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:101:4149)
  at Object.getFileProtocolModuleFormat [as file:] (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:149:1318)
  at defaultGetFormat (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:149:1953)
  at defaultLoad (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:153:1154)
  at ModuleLoader.load (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:154:3400)
  at ModuleLoader. (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:154:2452)
  at new ModuleJob (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:155:876)
  at #s (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:154:2337)
  at ModuleLoader.getJobFromResolveResult (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:154:2195)
  at ModuleLoader.getModuleJob (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:154:1965)
  at async ModuleLoader.import (https://noderu2nde-alzg.w-corp-staticblitz.com/builtins.ddb8d84d.js:154:2646)