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

fallbackCJS is not supported #59

Closed
dctalbot opened this issue Aug 4, 2024 · 5 comments
Closed

fallbackCJS is not supported #59

dctalbot opened this issue Aug 4, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@dctalbot
Copy link

dctalbot commented Aug 4, 2024

Bug description

I think something is amiss with the packaging configuration.

Description

  • I have a typical vitest setup file with this contents:
import failOnConsole from "vitest-fail-on-console"
failOnConsole()
  • I do not have {type: "module"} in my package.json
  • Changing the setup file to be named setup.mts did not help

Expected outcome

  • no error

Actual outcome

  • vitest errors with TypeError: default is not a function when using this package.

Screenshots / Video / StackTrace

@dctalbot dctalbot added the bug Something isn't working label Aug 4, 2024
@thomasbrodusch
Copy link
Owner

Hey @dctalbot thanks for raising a new issue!

As you are the first one raising that kind of issue can you provide a bit more of context:

  • your package.json
  • some screenshots, error stacktrace, ...

Thanks for using vitest-fail-on-console :)

@dctalbot
Copy link
Author

dctalbot commented Aug 15, 2024

vitest.config.mts:

import path from "path"
import { defineConfig } from "vitest/config"

export default () => {
  return defineConfig({
    test: {
      setupFiles: ["./test/setupVitest.ts"],
      server: {
        deps: {
          fallbackCJS: true,
        },
      },
    },
    resolve: {
      alias: {
        src: path.resolve(__dirname, "./src"),
        "@test": path.resolve(__dirname, "./test"),
      },
    },
  })
}

test/setupVitest.ts:

import failOnConsole from "vitest-fail-on-console"

failOnConsole()

console output:

my-project ✗ pnpm vitest run src/ui/Menu/Menu.test.tsx

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/ui/Menu/Menu.test.tsx [ src/ui/Menu/Menu.test.tsx ]
TypeError: default is not a function
 ❯ test/setupVitest.ts:3:1
      1| import failOnConsole from "vitest-fail-on-console"
      2| 
      3| failOnConsole()
       | ^
      4| 

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed (1)
      Tests  no tests
   Start at  16:48:04
   Duration  259ms (transform 17ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 60ms)

versions:
vite 5.3.5
vitest 2.0.5
vitest-fail-on-console 0.7.0
Node 18.18.2

@dctalbot
Copy link
Author

I think the issue may be with fallbackCJS: true which is documented as:

Try to guess the CJS version of a package when it's invalid ESM

Maybe the dist is detcted as invalid? Unfortunately, I need this setting as true in order to support other packages.

thomasbrodusch added a commit that referenced this issue Sep 2, 2024
We're shipping both `./dist/vitest-fail-on-console.es.js` and `./dist/vitest-fail-on-console.umd.js` with "type": "module".
Since Vitest only runs `esm` in the test environment (doesn't use require), we can only ship the default export as `./dist/vitest-fail-on-console.es.js`

Thanks to @hi-ogawa - vitest-dev/vitest#6352 (comment)
thomasbrodusch added a commit that referenced this issue Sep 2, 2024
We're shipping both `./dist/vitest-fail-on-console.es.js` and `./dist/vitest-fail-on-console.umd.js` with "type": "module".
Since Vitest only runs `esm` in the test environment (doesn't use require), we can only ship the default export as `./dist/vitest-fail-on-console.es.js`

Thanks to @hi-ogawa - vitest-dev/vitest#6352 (comment)
@thomasbrodusch
Copy link
Owner

Hi @dctalbot new fixing release v0.7.1 published & available on NPM 👌
It has been fixed in commit f45eecd, have a try and tell me if everything run smoothly as expected :)

@dctalbot dctalbot changed the title TypeError: default is not a function fallbackCJS is not supported Sep 5, 2024
@dctalbot
Copy link
Author

dctalbot commented Sep 5, 2024

Hey, thank you for looking at this issue! Unfortunately, v0.7.1 still exhibits the same behavior for me. I was able to unblock myself by reworking some other dependencies and setting fallbackCJS to false. Personally, this is no longer an issue, but other people may still run into this. I updated the issue title to reflect this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants