summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/tough-tigers-drum.md5
-rw-r--r--packages/astro/src/core/add/index.ts20
-rw-r--r--packages/integrations/lit/README.md8
3 files changed, 33 insertions, 0 deletions
diff --git a/.changeset/tough-tigers-drum.md b/.changeset/tough-tigers-drum.md
new file mode 100644
index 000000000..b82c4d224
--- /dev/null
+++ b/.changeset/tough-tigers-drum.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Add default `.npmrc` file when adding the Lit integration through `astro add lit` and using `pnpm`.
diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts
index 3abe00db9..55880a4c5 100644
--- a/packages/astro/src/core/add/index.ts
+++ b/packages/astro/src/core/add/index.ts
@@ -60,6 +60,10 @@ export default {
preprocess: vitePreprocess(),
};
`;
+const LIT_NPMRC_STUB = `\
+# Lit libraries are required to be hoisted due to dependency issues.
+public-hoist-pattern[]=*lit*
+`;
const OFFICIAL_ADAPTER_TO_IMPORT_MAP: Record<string, string> = {
netlify: '@astrojs/netlify/functions',
@@ -146,6 +150,22 @@ export default async function add(names: string[], { cwd, flags, logging, teleme
defaultConfigContent: SVELTE_CONFIG_STUB,
});
}
+ // Some lit dependencies needs to be hoisted, so for strict package managers like pnpm,
+ // we add an .npmrc to hoist them
+ if (
+ integrations.find((integration) => integration.id === 'lit') &&
+ (await preferredPM(fileURLToPath(root)))?.name === 'pnpm'
+ ) {
+ await setupIntegrationConfig({
+ root,
+ logging,
+ flags,
+ integrationName: 'Lit',
+ possibleConfigFiles: ['./.npmrc'],
+ defaultConfigFile: './.npmrc',
+ defaultConfigContent: LIT_NPMRC_STUB,
+ });
+ }
break;
}
case UpdateResult.cancelled: {
diff --git a/packages/integrations/lit/README.md b/packages/integrations/lit/README.md
index fe99f3e2f..bd3101a19 100644
--- a/packages/integrations/lit/README.md
+++ b/packages/integrations/lit/README.md
@@ -141,6 +141,14 @@ export default defineConfig({
The correct order might be different depending on the underlying cause of the problem. This is not guaranteed to fix every issue however, and some libraries cannot be used if you are using the Lit integration because of this.
+### Strict package managers
+
+When using a [strict package manager](https://pnpm.io/pnpm-vs-npm#npms-flat-tree) like `pnpm`, you may get an error such as `ReferenceError: module is not defined` when running your site. To fix this, hoist Lit dependencies with an `.npmrc` file:
+
+```ini title=".npmrc"
+public-hoist-pattern[]=*lit*
+```
+
### Limitations
The Lit integration is powered by `@lit-labs/ssr` which has some limitations. See their [limitations documentation](https://www.npmjs.com/package/@lit-labs/ssr#user-content-notes-and-limitations) to learn more.