React version: 17.0.1
Steps To Reproduce
- Create a new directory,
cd to it.
- Run
npm i react@17 webpack@5 webpack-cli@4
- Create
index.mjs with the following content:
import * as jsx from 'react/jsx-runtime';
console.log(jsx);
- Run
node index.mjs
- Run
npx webpack-cli path/to/index.mjs
- I had to use an absolute path on my machine or webpack-cli wouldn't find
index.mjs, don't know why.
Link to code example: --
The current behavior
> node index.mjs
node:internal/process/esm_loader:74
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'D:\repos\jsx\node_modules\react\jsx-runtime' imported from D:\repos\jsx\index.mjs
Did you mean to import react/jsx-runtime.js?
at new NodeError (node:internal/errors:277:15)
at finalizeResolution (node:internal/modules/esm/resolve:307:11)
at moduleResolve (node:internal/modules/esm/resolve:742:10)
at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:853:11)
at Loader.resolve (node:internal/modules/esm/loader:85:40)
at Loader.getModuleJob (node:internal/modules/esm/loader:229:28)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:51:40)
at link (node:internal/modules/esm/module_job:50:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
> npx webpack-cli D:\repos\jsx\index.mjs
[webpack-cli] Compilation finished
assets by status 264 bytes [cached] 1 asset
./index.mjs 64 bytes [built] [code generated]
ERROR in ./index.mjs 1:0-41
Module not found: Error: Can't resolve 'react/jsx-runtime' in 'D:\repos\jsx'
Did you mean 'jsx-runtime.js'?
BREAKING CHANGE: The request 'react/jsx-runtime' failed to resolve only because it was resolved as fully specified
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
webpack 5.4.0 compiled with 1 error in 150 ms
npm ERR! code 1
The expected behavior
No issues importing react/jsx-runtime with no file extensions.
I can think of two solutions:
- Fix babel, typescript, and all the other tools that automatically add the import to add the file extension.
- That ship has sailed though, I don't think this is right thing to do.
- Add the
exports field in react's package.json.
React version: 17.0.1
Steps To Reproduce
cdto it.npm i react@17 webpack@5 webpack-cli@4index.mjswith the following content:node index.mjsnpx webpack-cli path/to/index.mjsindex.mjs, don't know why.Link to code example: --
The current behavior
The expected behavior
No issues importing
react/jsx-runtimewith no file extensions.I can think of two solutions:
exportsfield in react'spackage.json.process.env.NODE_ENVfor bundlers.