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

Set babel config to use commonjs modules on server #61

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

penx
Copy link

@penx penx commented Nov 3, 2022

Fixes #60

Previously, if you had

export default function App({
  selectedId,
  isEditing,
  searchText,
  something = ['a', 'b'],
}) {
  const [a, b] = something;
  console.log(a, b);

this would error with

internal/modules/cjs/loader.js:1102
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /rsc/server-components-demo/node_modules/@babel/runtime/helpers/esm/slicedToArray.js
require() of ES modules is not supported.

This updates the babel config on the server to use useESModules: false

Previously, if you had

```js
export default function App({
  selectedId,
  isEditing,
  searchText,
  something = ['a', 'b'],
}) {
  const [a, b] = something;
  console.log(a, b);
```

this would error with

```console
internal/modules/cjs/loader.js:1102
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /rsc/server-components-demo/node_modules/@babel/runtime/helpers/esm/slicedToArray.js
require() of ES modules is not supported.
```

This updates the babel config on the server to use `useESModules: false`
The package lock in the repository is v2. Using fermium (14) sets it back to v1.

Instead, update the version of node in .nvmrc
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

Successfully merging this pull request may close these issues.

Can't use destructuring assignment in server code
1 participant