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

@nrwl/web: Rollup executor forces code output to be ES5 #8639

Closed
layershifter opened this issue Jan 21, 2022 · 3 comments · Fixed by #8907
Closed

@nrwl/web: Rollup executor forces code output to be ES5 #8639

layershifter opened this issue Jan 21, 2022 · 3 comments · Fixed by #8907
Assignees
Labels
outdated scope: react Issues related to React support for Nx type: bug

Comments

@layershifter
Copy link

layershifter commented Jan 21, 2022

Intro

I am using @nrwl/web executor:

{
  "targets": {
    "build": {
      "executor": "@nrwl/web:rollup",
      "options": {
        "compiler": "babel",
        "format": ["umd"]
      }
    }
  }
}

In my TS configs I am targeting ES2019:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "esnext"
  }
}

Current Behavior

UMD and CommonJS outputs are forced to use target: "es5" by this line:

...compilerOptions,
target: 'es5',

The following code is compiled:

function borderLeft(...values: any[]): any {
  return {
    borderLeftWidth: values[0],
    ...(values[1] && { borderLeftStyle: values[1] }),
    ...(values[2] && { borderLeftColor: values[2] }),
  };
}

⬇️⬇️⬇️

image

That matches ES5 output 🙃

Expected Behavior

I went through existing/closed issues (#3601, #4115) and fixes for them kept that line without changes.

As target: es2019 supports all features for that snippet I expect will not apply any transforms (as in playground):

image

Proposal

I think that it's reasonable to remove that line at all and respect user's configuration.

Steps to Reproduce

Manual steps

  • npx create-nx-workspace --preset=react
  • nx g @nrwl/react:library --publishable --importPath=test
  • put a function into to libs/test/src/lib/test.tsx
  • yarn nx run test:build
  • check dist/libs/test/index.umd.js

Ready to go

Environment

  Node : 16.13.1
  OS   : darwin arm64
  npm  : 8.1.2
  
  nx : 13.4.6
  @nrwl/angular : undefined
  @nrwl/cli : 13.4.6
  @nrwl/cypress : 13.4.6
  @nrwl/devkit : 13.4.6
  @nrwl/eslint-plugin-nx : 13.4.6
  @nrwl/express : undefined
  @nrwl/jest : 13.4.6
  @nrwl/linter : 13.4.6
  @nrwl/nest : undefined
  @nrwl/next : undefined
  @nrwl/node : undefined
  @nrwl/nx-cloud : undefined
  @nrwl/react : 13.4.6
  @nrwl/react-native : undefined
  @nrwl/schematics : undefined
  @nrwl/tao : 13.4.6
  @nrwl/web : 13.4.6
  @nrwl/workspace : 13.4.6
  @nrwl/storybook : 13.4.6
  @nrwl/gatsby : undefined
  typescript : 4.4.4
  rxjs : 6.6.7
  ---------------------------------------
  Community plugins:
@ndcunningham
Copy link
Contributor

Hey, when you create a library the default format is both UMD and ESM.

Based on your description you want the output to be ESM.

To achieve this you can:

  1. Add the ESM format to the format property of your library's project.json (for example: target: ['umd', 'esm'])
  2. When creating a library add the --buildable flag nx g @nrwl/react:library --publishable --buildable --importPath=test

After you build the library check the dist/libs/[lib-name]/**.esm.js

@layershifter
Copy link
Author

layershifter commented Jan 28, 2022

@ndcunningham Sorry, but I have a different issue 🙂

I can configure format and get umd & cjs outputs, this works ✅
The problem is that these outputs will always use es5 as target in TypeScript config and will ignore user's settings (i.e. there is no way to specify target: es2019 for these outputs).

Please check "Current Behavior" behavior section and "Steps to Reproduce".

@FrozenPandaz FrozenPandaz added the scope: react Issues related to React support for Nx label Jan 29, 2022
ndcunningham added a commit to ndcunningham/nx that referenced this issue Feb 9, 2022
When you use swc as the compiler for a library the types should be generated

ISSUES CLOSED: nrwl#8639
jaysoo pushed a commit that referenced this issue Feb 24, 2022
When you use swc as the compiler for a library the types should be generated

ISSUES CLOSED: #8639
meeroslav pushed a commit to meeroslav/nx that referenced this issue Mar 4, 2022
When you use swc as the compiler for a library the types should be generated

ISSUES CLOSED: nrwl#8639
@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: react Issues related to React support for Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants