allure-js icon indicating copy to clipboard operation
allure-js copied to clipboard

Failed to resolve "allure-vitest/reporter". This package is ESM only but it was tried to load by `require`.

Open dzianisMazhuhou opened this issue 1 year ago • 1 comments

Describe the bug Failed to resolve "allure-vitest/reporter". This package is ESM only but it was tried to load by require. See https://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details. [plugin externalize-deps]

node_modules/esbuild/lib/main.js:1374:27:
  1374 │         let result = await callback({

This error came from the "onResolve" callback registered here:

node_modules/esbuild/lib/main.js:1293:20:
  1293 │       let promise = setup({

The plugin "externalize-deps" was triggered by this import

vitest.config.ts:1:332:
  1 │ /vitest.config.ts";import AllureReporter from 'allure-vitest/reporter'

To Reproduce Steps to reproduce the behavior:

  1. npm install --save-dev allure-commandline
  2. npm install --save-dev allure-vitest
  3. npx vitest myTest.test.ts

Additional context

If you follow the link indicated in the error, they advise converting your config to ESM by either:

  • adding "type": "module" to the nearest package.json
  • renaming vite.config.js/vite.config.ts to vite.config.mjs/vite.config.mts

Is there another way to fix it?

dzianisMazhuhou avatar Feb 15 '24 13:02 dzianisMazhuhou

Hey there!

Unfortunately, there is no way to use allure-vitest outside an ESM module because the API provided by vitest has esm format, which isn't compatible with cjs at all.

By the way, vitest now prints a warning, that cjs compatibility will be deprecated soon, so I don't know, is it reasonable to try to do something.

epszaw avatar Feb 16 '24 11:02 epszaw