-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
@it-astro:when cannot be resolved in npm workspaces setup #186
Comments
This error happens when the Astro When integration is not loaded. There is nothing that the integration can do to fix a problem when it is not loaded. You can run your build with the environment variable |
Thanks for feedback. So I added explicit addon to > [email protected] dev
> astro dev
inox-tools:astro-when Adding Vite plugin +0ms
inox-tools:astro-when Adding Vite plugin +0ms
09:51:01 [WARN] [@inox-tools/astro-when] The Vite plugin "@inox-tools/astro-when" is already present in your Vite configuration, this plugin may not behave correctly.
09:51:01 [WARN] [@astrojs/cloudflare] [@astrojs/cloudflare] This adapter is intended to be used with server rendered pages, which this project does not contain any of. As such, this adapter is unnecessary.
09:51:01 [WARN] [config] The adapter @astrojs/cloudflare has limited support for "sharp". Certain features may not work as expected.
inox-tools:astro-when Injecting types in .astro structure +3ms
inox-tools:astro-when Injecting types in .astro structure +0ms
09:51:01 [types] Generated 0ms
astro v5.1.1 ready in 631 ms
┃ Local http://localhost:3000/
┃ Network use --host to expose
09:51:01 [content] Syncing content
09:51:01 [content] Synced content
09:51:01 watching for file changes...
warn - No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.
warn - https://tailwindcss.com/docs/content-configuration
09:51:13 [ERROR] [MiddlewareCantBeLoaded] An unknown error was thrown while loading your middleware.
Error reference:
https://docs.astro.build/en/reference/errors/middleware-cant-be-loaded/
Stack trace:
at /Users/przemek/dev/astro-5-cf-repro/projects/astro-on-cloudflare/Users/przemek/dev/astro-5-cf-repro/node_modules/astro/dist/core/middleware/loadMiddleware.js:8:24
[...] See full stack trace in the browser, or rerun with --verbose.
Caused by:
Invalid module "@it-astro:when" is not a valid package name imported from /Users/przemek/dev/astro-5-cf-repro/node_modules/@astrojs/cloudflare/dist/entrypoints/middleware.js
at parsePackageName (node:internal/modules/esm/resolve:782:11)
at moduleResolve (node:internal/modules/esm/resolve:927:18)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
at link (node:internal/modules/esm/module_job:86:36) From CF: export default function createIntegration(args) {
let _config;
const cloudflareModulePlugin = cloudflareModuleLoader(args?.cloudflareModules ?? true);
return {
name: '@astrojs/cloudflare',
hooks: {
'astro:config:setup': ({ command, config, updateConfig, logger, addWatchFile, addMiddleware, }) => {
updateConfig({
build: {
client: new URL(`.${wrapWithSlashes(config.base)}`, config.outDir),
server: new URL('./_worker.js/', config.outDir),
serverEntry: 'index.js',
redirects: false,
},
vite: {
plugins: [
// https://developers.cloudflare.com/pages/functions/module-support/
// Allows imports of '.wasm', '.bin', and '.txt' file types
cloudflareModulePlugin,
{
name: 'vite:cf-imports',
enforce: 'pre',
resolveId(source) {
if (source.startsWith('cloudflare:')) {
return { id: source, external: true };
}
return null;
},
},
],
},
integrations: [astroWhen()],
image: setImageConfig(args?.imageService ?? 'compile', config.image, command, logger),
}); |
I still can't reproduce the problem, even with your reproduction project, but it seems from your logs that the integration is being added twice. As the warning shows, having it twice is not supported and may misbehave:
|
https://github.com/psmyrdek/astro-5-cf-repro/actions/runs/13112878566/job/36580449315 Just added example workflow to reproduce the issue. After launching dev server I'm making a generic GET to localhost:3000 to prove that the page cannot be loaded. |
I did manage to reproduce with the same commands as GH Actions. It seems Vite is having a problem resolving references on an NPM workspace during dev. Since Vite uses esbuild for dev server and rollup for prod builds this problem might be on esbuild, but I'd report it on Vite first. Installing the dependencies in the project itself work fine, and so does using PNPM or Yarn workspaces. All of those have the dependencies on PNPM and Yarn workspaces both use linking to have a It is not in the scope of the package to workaround the messy state of JS package managers and bundlers not working with each other and each doing its own thing, so I'm gonna close this. Sorry. |
Hi there and Happy New Year!
For quite some time I've been struggling with Astro Cloudflare adapter (11+) being unable to resolve "@it-astro:when" package in a setup based on npm workspaces. Would it be able to provide different types/modules that adapter would import to avoid clashes with this package? Happy to hear your thoughts!
https://github.com/psmyrdek/astro-5-cf-repro
From:
node_modules/@astrojs/cloudflare/dist/entrypoints/middleware.js
Problematic line:
import { When, whenAmI } from '@it-astro:when';
Ref: withastro/adapters#343
The text was updated successfully, but these errors were encountered: