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

unable to alias modules using Vitest/Vite #1638

Closed
6 tasks done
TeemuKoivisto opened this issue Jul 14, 2022 · 4 comments · Fixed by #1673
Closed
6 tasks done

unable to alias modules using Vitest/Vite #1638

TeemuKoivisto opened this issue Jul 14, 2022 · 4 comments · Fixed by #1673

Comments

@TeemuKoivisto
Copy link

Describe the bug

I am replacing my old Jest tests with Vitest (awesome work btw) but I am unable to alias a module in similar manner. Failing to do so the different versions conflict and crash, failing the test. This might be more related to Vite but I succeeded aliasing the same module using just Vite so I'm not sure what's the cause of the problem.

Reproduction

https://github.com/TeemuKoivisto/vite-unable-to-alias-module

System Info

System:
    OS: macOS 11.5.2
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Memory: 232.34 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.14.0/bin/yarn
    npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
  Browsers:
    Chrome: 103.0.5060.114
    Firefox: 102.0
    Safari: 14.1.2
  npmPackages:
    vite: ^3.0.0 => 3.0.0 
    vitest: ^0.18.0 => 0.18.0

Used Package Manager

pnpm

Validations

@sheremet-va
Copy link
Member

Haven't tested it, but @manuscripts/manuscript-transform is not ESM package, and it loads cjs version of prosemirror-model, while when you directly import it in a test ESM version is loaded.

Try adding @manuscripts/manuscript-transform to test.deps.inline.

@TeemuKoivisto
Copy link
Author

Hey thanks for advice! Hmm adding it to the inline list I get another error:

TypeError: exports.hasOwnProperty is not a function
 ❯ __exportStar node_modules/.pnpm/@manuscripts+manuscript-transform@0.49.4/node_modules/@manuscripts/manuscript-transform/dist/cjs/index.js:10:54
      8| }));
      9| var __exportStar = (this && this.__exportStar) || function(m, exports) {
     10|     for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exp…
       |                                                      ^
     11| };
     12| Object.defineProperty(exports, "__esModule", { value: true });

I have succeed in loading @manuscripts/manuscript-transform with Vite without duplicating prosemirror-model using alias before so I'm really baffled why it's breaking now.

@rgripper
Copy link

rgripper commented Jul 17, 2022

I suspect I have the same issue. Preact alias is not applied when running vitest against a third-party library that itself imports react. But vite itself builds and runs without an issue.
Here is a tiny repro:
https://github.com/rgripper/bug-demo

And the error (it is from slightly different source code)

TypeError: Cannot read properties of null (reading 'useState')
 ❯ useState ../../node_modules/.pnpm/react@18.2.0/node_modules/react/cjs/react.development.js:1622:21
 ❯ d.N [as constructor] ../../node_modules/.pnpm/@headlessui+react@1.6.6/node_modules/@headlessui/react/dist/components/switch/switch.js:1:857
 ❯ d.O [as render] ../../node_modules/.pnpm/preact@10.10.0/node_modules/preact/dist/preact.mjs:1:8158

@sheremet-va
Copy link
Member

sheremet-va commented Jul 18, 2022

@rgripper Code of deps is not runing through Vite pipeline. At the moment we don't have a good solution for this. To fix this, you can use deps.inline option.

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

Successfully merging a pull request may close this issue.

3 participants