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

Extracting fails when next/dynamic is used #1058

Closed
datagutt opened this issue May 11, 2021 · 2 comments
Closed

Extracting fails when next/dynamic is used #1058

datagutt opened this issue May 11, 2021 · 2 comments

Comments

@datagutt
Copy link

Describe the bug
When using Next.js dynamic imports, Lingui is unable to extract messages from the pages/components using dynamic imports.

To Reproduce
Steps to reproduce the behavior, possibly with minimal code sample, e.g:

import { Trans } from "@lingui/react"
import dynamic from "next/dynamic"
const TranslatedComponent = dynamic(() => import("../components/TranslatedComponent"))

export default function Index() {
   return (<div><TranslatedComponent /></div>
}

When extracting pages/index.js, i get this error:
Cannot process file app/pages/index.js: Cannot read property 'pagesDir' of undefined

Expected behavior
Messages are extracted from pages using dynamic components.

Additional context

This used to work fine in Next.js 10.1, but broke in 10.2. Likely related to this:
PR: vercel/next.js#24281
Issue: vercel/next.js#24566

  • jsLingui version 3.8.10
  • Babel version 7.14.0
  • Your Babel config (e.g. .babelrc) or framework you use (Create React App, Meteor, etc.)
    Next.JS 10.2
@semoal
Copy link
Contributor

semoal commented May 11, 2021

Actually crashes internally Next but extracts correctly the value to the messages file. (Tried with @canary version of Next and the latest)

Actually the fix from our side is to remove the Typescript extractor located here: https://github.com/lingui/js-lingui/blob/main/packages/cli/src/api/extractors/index.ts#L6, we already discussed this on #1047 and probably we I can find some free hours I'll work hard on a next version of Lingui will all these bugs fixed.

On my head I want to add a similar API of Jest to add any extractors :)

@semoal
Copy link
Contributor

semoal commented May 18, 2021

Released 3.9.0 give it a try when you can, but i'm pretty sure that will fixed :)

@semoal semoal closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants