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

When upgrading from 1.4.0 to 1.5.0, an error related to CommonJS modules appears. #5555

Closed
6 tasks done
rayhomie opened this issue Apr 16, 2024 · 4 comments
Closed
6 tasks done

Comments

@rayhomie
Copy link

Describe the bug

image

FAIL tests/alipay/_util/tests/useHandleCustomEvent.spec.ts [ tests/alipay/_util/tests/useHandleCustomEvent.spec.ts ]
SyntaxError: Named export 'render' not found. The requested module './node_modules/preact-render-to-string/dist/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from './node_modules/preact-render-to-string/dist/index.js';
const { render: serverRender } = pkg;

Reproduction

https://github.com/ant-design/ant-design-mini/actions/runs/8686918943/job/23819371194

System Info

System:
    OS: macOS 13.4.1
    CPU: (8) arm64 Apple M1
    Memory: 101.98 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.0 - /usr/local/bin/node
    npm: 10.2.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 123.0.6312.124
    Safari: 17.1.2
  npmPackages:
    @vitest/coverage-istanbul: ^1.1.1 => 1.5.0 
    vitest: ^1.5.0 => 1.5.0

Used Package Manager

npm

Validations

@hi-ogawa
Copy link
Contributor

Can you provide smaller reproduction? With that size of repo and without English, we cannot take any actions on your issues.

Copy link

Hello @rayhomie. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@rayhomie
Copy link
Author

Can you provide smaller reproduction? With that size of repo and without English, we cannot take any actions on your issues.

https://github.com/rayhomie/vitest-bug-report

clone this repo, and read README.md

@hi-ogawa hi-ogawa changed the title 从1.4.0升级到1.5.0,出现CommonJS modules 相关报错 When upgrading from 1.4.0 to 1.5.0, an error related to CommonJS modules appears. Apr 17, 2024
@hi-ogawa
Copy link
Contributor

This error is probably due to this change:

To get the previous behavior, can you try server.deps.inline?
https://stackblitz.com/edit/github-ocsroc?file=vite.config.ts

{
  test: {
    server: {
      deps: {
        inline: [/functional-mini/],
      },
    }
  }
}

The underlying issue seems to be that you package re-exports preact somewhere, but the way it's done doesn't seems to be NodeJS esm compliant.

// node repro.mjs
import { alipayComponent } from 'functional-mini/component';
console.log(alipayComponent);
file:///home/projects/github-ocsroc/node_modules/functional-mini/dist/esm/3rd-party/preact.js:5
export { render as serverRender } from './node_modules/preact-render-to-string/dist/index.js';
         ^^^^^^
SyntaxError: The requested module './node_modules/preact-render-to-string/dist/index.js' does not provide an export named 'render'
    at ModuleJob._instantiate (https://githubocsroc-4qyz.w-credentialless-staticblitz.com/blitz.7dbe22a9.js:181:1509)
    at async ModuleJob.run (https://githubocsroc-4qyz.w-credentialless-staticblitz.com/blitz.7dbe22a9.js:181:2327)

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

No branches or pull requests

2 participants