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.

🐛 dev server vite 2.2.3 dynamic import are not using path aliases

See original GitHub issue

Current behavior

importsToLoad dynamic import of the spec file fails because it does not replace the path alias given by vite in the dynamic import.

https://github.com/cypress-io/cypress/blob/e5385fe413ae866985c04dfc991f8378673c6159/npm/vite-dev-server/client/initCypressTests.js#L9

This results in a TypeError when it resolves.

Desired behavior

When vite is used and path aliases are given, check all kinds of imports or references to files with the according path alias.

Test code to reproduce

src/components/QuasarButton.vue

<template>
  <input
    data-cy="button"
    label="test emit"
    @click="$emit('test')"
  />
</template>

<script>
import { defineComponent } from 'vue';

export default defineComponent({
  name: 'QuasarButton',
  emits: ['test'],
});

src/components/__test__/QuasarButton.spec.ts

// __test__/QuasarButton.spec.ts

and a path alias for src pointing to src

Cypress Version

10.1.0

Other

The content does not really matter because cypress will not reach any of it because vite has found spec files and is providing the paths with knowing the path alias for it but not resolving it but initCypresssTests is blind to it and will fail trying to dynamically import from the path given by vite.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:28 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
lmiller1990commented, Sep 22, 2022

https://github.com/cypress-io/cypress/pull/23605 landed, it’ll be in the next release, I hope this helps!

We can keep working on this, I want to enable third parties as much as possible.

1reaction
IlCallocommented, Oct 11, 2022

I’m back at it 😁 Seems like the support for async webpack config did the trick, so this issue can be closed We’re now dealing with another problem, but I’ll open a dedicated issue about it

Read more comments on GitHub >

github_iconTop Results From Across the Web

src alias in vite/vue project with @ symbol not working
Your alias definition is fine, but you are missing a details about importing dynamic assets with Vite. I already explained it in this...
Read more >
require is not defined vite | The Search Engine You Control
I need to use the dayjs library in my Vue application but Vite does not allow me to use require as specified in...
Read more >
Changelog - Cypress Documentation
The error "Automatic publicPath is not supported in this browser" will no longer be displayed when using Webpack 5 and dynamic imports. Fixes...
Read more >
packages/vite/CHANGELOG.md · Gitee 极速下载/ViteJS
renderBuiltUrl will also get called for preload asset paths. And build.modulePreload.resolveDependencies will be called both for JS dynamic imports preload ...
Read more >
Building for Production - Vite
In this case, you can use the globally injected import.meta.env.BASE_URL variable which will be the public base path. Note this variable is statically...
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