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

build: babel-postprocess triggers warnings for packages using swc #27304

Closed
Hotell opened this issue Mar 23, 2023 · 3 comments · Fixed by #27313
Closed

build: babel-postprocess triggers warnings for packages using swc #27304

Hotell opened this issue Mar 23, 2023 · 3 comments · Fixed by #27313

Comments

@Hotell
Copy link
Contributor

Hotell commented Mar 23, 2023

looks like we missed some issues while enabling babel-plugin-module-resolver.

Every package that uses @griffel transform will trigger following babel warnings:

image

Initially I thought that this is caused by not all packages are aware about our module-resolver (those that don't use @griffel) and to fix this we should add module-resolver to very package that is using babel.

Based on more deep investigation that assumption was wrong as the issues seems more complicated.

Why is this happening

griffel babel processing works as babel internally emits every file with module-resolve, then transforms makeStyles , and emits back original file without module-resolve applied but with correct makeStyles transform.

Now because babel transforms every file in isolated context( file by file ), when second file is transformed and that file contains in its import tree previously internally transformed file, it will trigger warning Could not resolve "packages/react-components/react-theme/lib/index.js" in file ~/packages/react-components/react-text/lib/components/presets/Subtitle2Stronger/Subtitle2Stronger.js.

To easily repro this outside griffel context all that is needed is to directly use module-resolver like this:

within packages/react-components/react-text/.babelrc.json:

{
"plugins": [
    [
      "babel-plugin-module-resolver",
      {
        "root": ["../../../"],
        "alias": {
          "@fluentui/tokens": "packages/tokens/lib/index.js",
          "^@fluentui/(?!react-icons)(.+)": "packages/react-components/\\1/lib/index.js"
        }
      }
    ],

    "annotate-pure-calls",
    "@babel/transform-react-pure-annotations"
  ]
}

now we can run yarn workspace @fluentui/react-text babel lib/ -d dist/lib

image

Originally posted by @Hotell in #27250 (comment)

@Hotell Hotell changed the title looks like we missed few packages. packages without mapping trigger babelpostprocess errors build: babel-postprocess triggers warnings for packages using swc Mar 23, 2023
@Hotell Hotell self-assigned this Mar 23, 2023
@Hotell
Copy link
Contributor Author

Hotell commented Mar 23, 2023

wondering if this is expected behaviour (that there are issues but babel finishes with success) ? cc @layershifter

@ling1726
Copy link
Member

@Hotell why does this only occur with SWC and not with our previoust tsc setup?

Also is the latest release with swc transpilation impacted (9.18.3)?

@Hotell
Copy link
Contributor Author

Hotell commented Mar 24, 2023

@Hotell why does this only occur with SWC and not with our previoust tsc setup?

Because of griffel (linaria) not supporting swc cjs #26251

Also is the latest release with swc transpilation impacted (9.18.3)?

Nothing should be impacted in production. As I mention in the issue, griffel preset is able to find re-mapped path to esm transpiled output and apply transforms.

@msft-fluent-ui-bot msft-fluent-ui-bot added Status: Fixed Fixed in some PR and removed Status: In PR labels Mar 29, 2023
@microsoft microsoft locked as resolved and limited conversation to collaborators Apr 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants