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

Support for PNPM (astro-i18next throws with "module is not defined") #48

Open
Alexandre-Fernandez opened this issue Oct 7, 2022 · 2 comments

Comments

@Alexandre-Fernandez
Copy link
Contributor

Alexandre-Fernandez commented Oct 7, 2022

When I try to use <Trans />, <HeadHrefLangs />, <LanguageSelector />, interpolate, etc I get the following error :

module is not defined

/@fs/my/local/directories/turborepo-astro-nestjs/node_modules/.pnpm/deepmerge@4.2.2/node_modules/deepmerge/dist/cjs.js:133:1

ReferenceError: module is not defined
    at /my/local/directories/turborepo-astro-nestjs/node_modules/.pnpm/deepmerge@4.2.2/node_modules/deepmerge/dist/cjs.js:133:1
    at instantiateModule (file:///my/local/directories/turborepo-astro-nestjs/node_modules/.pnpm/vite@3.1.6/node_modules/vite/dist/node/chunks/dep-db16f19c.js:53436:15

I'm using pnpm and turborepo, reproduction (error at apps/frontend/src/layouts/Layout.astro line 2 & 19):
https://github.com/Alexandre-Fernandez/turborepo-astro-nestjs

Astro app is located in /apps/frontend, commands to get the error :

EDIT:

This might happen because it's trying to load from the monorepo root /node_modules instead of its corresponding workspace /apps/frontend/node_modules.
I say that because I get a different error (another missing dependency) when I install deepmerge@4.2.2 in the root package.json (pnpm add deepmerge@4.2.2 -w).
This only happens with astro-i18next and not with i18next.

@Alexandre-Fernandez Alexandre-Fernandez changed the title astro-i18next/components throws with "module is not defined" Support for monorepos (astro-i18next/components throws with "module is not defined") Oct 7, 2022
@Alexandre-Fernandez Alexandre-Fernandez changed the title Support for monorepos (astro-i18next/components throws with "module is not defined") Support for monorepos (astro-i18next throws with "module is not defined") Oct 8, 2022
@Alexandre-Fernandez Alexandre-Fernandez changed the title Support for monorepos (astro-i18next throws with "module is not defined") Support for PNPM (astro-i18next throws with "module is not defined") Oct 8, 2022
@Alexandre-Fernandez
Copy link
Contributor Author

Alexandre-Fernandez commented Oct 8, 2022

Apparently the problem are not monorepos but PNPM.
I made a new reproduction here :
https://github.com/Alexandre-Fernandez/astro-i18next-issue-48

If you install with npm install it works, but if you install with pnpm install you get the module not defined error.

Workaround

Add this file to your root :

/.npmrc

public-hoist-pattern[]="*deepmerge*"
public-hoist-pattern[]="*proload*"
public-hoist-pattern[]="*locale-emoji*"

https://pnpm.io/npmrc#public-hoist-pattern

@millette
Copy link

While I haven't used the module yet, I'm a big fan of both astro and pnpm so I had a quick look at the source.

First thing I notice is these 2 imports:

cli/utils.ts:import { AstroI18nextConfig } from "types";
cli/generate.ts:import { AstroI18nextConfig } from "types";

Both should probably import from "./types" (or ./types.ts - I never know if the extension is required).

Other than that, I see these imports, all from dev deps. Probably should be regular deps:

cli/utils.ts:import { fdir, PathsOutput } from "fdir"; // dev dep
index.ts:import { AstroIntegration } from "astro"; // dev dep
cli/middlewares.ts:import { MiddlewareFunction } from "yargs"; // dev dep
cli/index.ts:import yargs from "yargs"; // dev dep
cli/index.ts:import { hideBin } from "yargs/helpers"; // dev dep
cli/utils.ts:import fsExtra from "fs-extra"; // dev dep
cli/utils.ts:import ts from "typescript"; // dev dep

With those fixes, pnpm might be happy without resorting to public-hoist-patterns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants