-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
ESM dependencies are not resolved correctly during build #4692
Comments
Is this fixed using |
This seems to work 👍. Do you know why it's required for Also, once I got past that error I ran into another one which seems to be caused by improper hoisting in the
|
If I had to guess, this line is probably causing it: https://github.com/withastro/astro/blob/main/packages/integrations/solid/src/index.ts#L42 can you try commenting that out in your local node_modules and see if it fixes any of those issues? |
Just tried it, still ran into the original issue. |
I ran into this problem with the @codesandbox/sandpack-react package.
|
@ruhollahh that's likely unrelated. |
I downgraded the astro version from 1.1.7 to 1.0.0-beta.73 and removed this: |
Just tried |
Okay I finally fixed the build problem by finding the the relevant package (in your case "solid-use") in node_modules folder and adding this to it's package.json file: |
There are two current workarounds that don't require altering affected packages: Matthew's suggestion of: {
vite: {
ssr: {
noExternal: ["solid-use"]
}
}
} and also one that I had posted on the Discord server when I opened the issue: {
vite: {
resolve: {
alias: {"solid-use": "D:/DemoProject/node_modules/solid-use/dist/esm/production/index.js"}
}
}
} The first one is better since it wouldn't require multiple entries for nested imports. |
Is this a problem only in build but not in development mode? |
Yes, that's correct. Same with the hoisting issue I mentioned in my second post, however, I haven't found a workaround for that issue yet. |
Seems like this might have something to do with monorepos/workspaces. Just tried out the latest > astro dev
file:///D:/DemoProject/node_modules/@astrojs/markdown-remark/dist/rehype-collect-headings.js:2
import { toHtml } from "hast-util-to-html";
^^^^^^
SyntaxError: Named export 'toHtml' not found. The requested module 'hast-util-to-html' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'hast-util-to-html';
const { toHtml } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:528:24)
npm ERR! Lifecycle script `dev` failed with error:
npm ERR! Error: command failed
npm ERR! in workspace: @enteleform/[email protected]
npm ERR! at location: D:/DemoProject
* The terminal process "C:/WINDOWS/System32/cmd.exe /d /c npm run dev" terminated with exit code: 1. |
Actually, just noticed that that same issue ( I haven't changed anything in the project other than running |
Are you using |
I think "nohoist": [
"**/astro", "**/astro/**"
"**/@vivliostyle/cli", "**/@vivliostyle/cli/**",
] Before that I was trying to go about it more granularly by targeting the clashing packages via |
I think this is more of a rollup error. |
https://www.npmjs.com/package/@rollup/plugin-commonjs something like this shall help? |
I tried that and a couple of Vite-specific ones without any luck.
The issue doesn't occur in other Vite projects though, even a plain Vite starter - so it seems like the issue might have something to do with Astro's particular usage of Vite/Rollup. |
|
What version of
astro
are you using?1.1.7
Are you using an SSR adapter? If so, which one?
no
What package manager are you using?
npm
What operating system are you using?
Windows
Describe the Bug
This error occurs during
build
when multi-distribution (CJS, ESM) packages are imported.I included two demos in the reproduction repo, one using
astro
and one usingsolid-start
. Both demos are minimally modified starter projects, they were updated to implementatom
fromsolid-use
instead ofcreateSignal
fromsolid-js
.The
solid-start
demo builds without issue. (they also usevite
in their build process)The
astro
demo throws the above error.solid-use
has both CJS & ESM distributions, with a properly configured package.json that should allow usage in either environment.Link to Minimal Reproducible Example
https://github.com/enteleform-codesandbox/0015--Astro--ESM-Imports
Participation
The text was updated successfully, but these errors were encountered: