-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Show better suggestions when CJS module resolution fails #26652
Comments
In v16 and older, you need to use the classic JSX transform: {
"compilerOptions": {
"jsx": "react",
"jsxFactory": "React.createElement",
"jsxFragmentFactory": "React.Fragment"
}
} You'll also need to add |
Oops, thank you for pointing out! % deno run app.tsx
error: Unable to load /path/to/Library/Caches/deno/npm/registry.npmjs.org/react-dom/16.8.5/server imported from file:///path/to/app.tsx
Caused by:
No such file or directory (os error 2) |
It looks like import server from "react-dom/server.js";
const { renderToStaticMarkup } = server; |
Thanks, it works! MEMO: |
The Import Maps is cool. {
"imports": {
"react": "npm:react@16.8.5",
"react-dom": "npm:react-dom@16.8.5",
+ "react-dom/server": "npm:react-dom@16.8.5/server.js"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
}
} |
@Hajime-san is there anything actionable here for us then? |
@bartlomieju error: Unable to load /path/to/Library/Caches/deno/npm/registry.npmjs.org/react-dom/16.8.5/server imported from file:///path/to/app.tsx
Caused by:
No such file or directory (os error 2)
hint: The module that you want to import is CommonJS.
Consider adding the extension as shown below and going through the default import.
import cool from "foo/bar.js";
const { something } = cool; BTW, I saw some PR is going that improves CJS module resolution now. |
No, this is not a bug. This is because this is ESM importing a CJS package. Similar errors occur in Node when importing from ESM:
Then when importing with an extension:
And finally solved by using the default import: > cat app.mjs
import server from 'react-dom/server.js';
console.log(server.renderToStaticMarkup);
V:\scratch\example
> node app.mjs
[Function: renderToStaticMarkup] |
I think it would be nice if Deno suggested to import server.js similar to node, as you suggested and then to suggest to use the default import in case it's not doing it. |
@dsherret |
React
Note: Former error is not a |
Updated:
When importing CJS from ESM, there are cases where the module cannot be resolved.
In such cases, an appropriate message will be displayed so that the user can correct the code.
Node.js example below.
Deno's result.
enivironment
Steps to reproduce
Old
It fails to import a slightly older version of
React
.OTOH, it works fine with the latest(
18.3.1
) version.enivironment
Steps to reproduce
The text was updated successfully, but these errors were encountered: