question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[0.20.2]: Tets fails if importing `tslib`

See original GitHub issue

Describe the bug

After upgrading to v0.20.x, most of my tests are now failing with:

SyntaxError: Named export '__assign' not found. The requested module 'tslib' 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 'tslib';
const { __assign } = pkg;

It’s caused by framer-motion using tslib. The package does include an exports field and module support, so a bit weird why this is popping up. Thinking it’s related to how node modules are resolved now after #1673.

Reproduction

The issue can be replicated by importing <framer-motion> in a test file. https://stackblitz.com/edit/vitest-dev-vitest-ue9bu2?file=test/App.test.tsx

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
  npmPackages:
    @vitejs/plugin-react: ^1.3.2 => 1.3.2 
    vite: ^2.9.9 => 2.9.14 
    vitest: 0.20.2 => 0.20.2

Used Package Manager

npm

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:7
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
thebuildercommented, Jul 31, 2022

Setting deps.registerNodeLoader to false (to skip the new Node logic) allows the test to run again.

1reaction
sheremet-vacommented, Aug 5, 2022

Upgrading vitest to v0.21.0 now solves the issue.

Technically this PR should also work with registerNodeLoader enabled, but performance might suffer for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

tslib should follow standards for ESM/CJS detection · Issue #173
Due to lack of standards support, it has to be special-cased in a number ... [0.20.2]: Tets fails if importing tslib vitest-dev/vitest#1753.
Read more >
"This syntax requires an imported helper but module 'tslib ...
If you see this error the first time you open a new project or repository, you probably simply haven't installed the app's required...
Read more >
Release Notes — pandas 0.20.2 documentation - PyData |
This is the list of changes to pandas between each release. ... Panel.to_frame() no longer fails when major_axis is a MultiIndex (GH5402).
Read more >
This syntax requires an imported helper but module 'tslib ...
To solve the error "This syntax requires an imported helper but module 'tslib' cannot be found", install tslib by running npm install -D...
Read more >
jasmine an error was thrown in afterall - You.com
If you don't know which test is causing the error, you can write xdescribe instead of describe for all tests and this will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found