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: astro build fails in npm workspace only #3820

Closed
1 task
altano opened this issue Jul 5, 2022 · 3 comments · Fixed by #3869
Closed
1 task

🐛 BUG: astro build fails in npm workspace only #3820

altano opened this issue Jul 5, 2022 · 3 comments · Fixed by #3869
Assignees
Labels
- P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)

Comments

@altano
Copy link
Contributor

altano commented Jul 5, 2022

What version of astro are you using?

1.0.0-beta.63

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Linux (Ubuntu focal)

Describe the Bug

If I add a basic astro project and then try to use the experimental @astrojs/image plugin, it works just fine. I can build and I have no problems. If I move the project to an npm workspace (that has no other projects and is otherwise empty other than the astro project I'm moving) build fails with the error:

$ npm run build --workspaces

> [email protected] build
> astro build

08:37:42 PM [build] Collecting build information...
08:37:42 PM [build] Completed in 39ms.
08:37:42 PM [build] Building entrypoints for prerendering...
08:37:44 PM [build] Completed in 2.24s.

 generating static routes 
 error   Unknown file extension ".astro" for /home/alan/src/astro-workspace-problem/node_modules/@astrojs/image/components/Image.astro
  Hint:
    You likely need to add this package to `vite.ssr.noExternal` in your astro config file.
stacktrace
  Stacktrace:
    at new NodeError (node:internal/errors:371:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:87:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:102:38)
    at defaultLoad (node:internal/modules/esm/load:21:14)
    at ESMLoader.load (node:internal/modules/esm/loader:359:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:280:58)
    at new ModuleJob (node:internal/modules/esm/module_job:66:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:297:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:261:34)
    at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:81:21)

npm ERR! Lifecycle script `build` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: [email protected] 
npm ERR!   at location: /home/alan/src/astro-workspace-problem/apps/astro-project 

This repo demonstrates the problem: https://github.com/altano/astro-workspace-problem (after cloning just run npm i && npm run build --workspaces)

I'm using Node v16.14.2 and npm v8.5.0

Link to Minimal Reproducible Example

https://github.com/altano/astro-workspace-problem

Participation

  • I am willing to submit a pull request for this issue.
@altano
Copy link
Contributor Author

altano commented Jul 5, 2022

Note that the guidance to add the package to noExternal does fix the build:

export default defineConfig({
  integrations: [image()],
  vite: {
    ssr: {
      noExternal: ["astro", "@astrojs/image"],
    },
  },
});

This still seems like a problem though since we shouldn't need to change the ssr config to run in an npm workspace, right?

@natemoo-re
Copy link
Member

Going to have @tony-sull take a look at this, you definitely shouldn't need to update your config to use the package.

@natemoo-re natemoo-re added - P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority) s1-small labels Jul 8, 2022
@tony-sull
Copy link
Contributor

Ah ha! Astro tries to catch known astro packages and automatically add them to the noExternal list, looks like it doesn't support how node_modules work in npm workspaces

Here it's expecting to find the @astrojs/image without checking node_modules up the tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P5: urgent Fix build-breaking bugs affecting most users, should be released ASAP (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants