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

Package subpath './environments' is not defined by "exports" #509

Closed
dtoxvanilla1991 opened this issue Aug 2, 2023 · 6 comments
Closed

Comments

@dtoxvanilla1991
Copy link

dtoxvanilla1991 commented Aug 2, 2023

Followed the guide to the T on the setup on nuxt-vitest. Getting this error:
Framework Nuxt3, Node v16.19.0
image
script part of the Component looks like this:

<script setup lang="ts">
import { Appeal } from "types";
import { useActiveImg } from "../../stores/activeImg";

const props = defineProps<{
  appeal: Appeal;
}>();

const active = useActiveImg();
</script>

<style scoped>
img.active {
  view-transition-name: selected-appeal;
  contain: layout;
}
</style>

test file:

// @vitest-environment nuxt
import { expect, test } from "vitest";
import { mount } from "@vue/test-utils";
import Card from "./Card.vue";
import { mountSuspended } from "vitest-environment-nuxt/utils";

test("my test", () => {
  const wrapper = mountSuspended(Card, {
    props: {
      appeal: {
        title: "APPEAL TITLE",
      },
    },
  });
  // expect(wrapper.vm).toBeTruthy();
});

package.json deps:

{
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare",
    "storybook": "storybook dev -p 8008",
    "build-storybook": "storybook build",
    "test": "vitest",
    "test:ui": "vitest --ui",
    "coverage": "vitest run --coverage",
    "lint:prettier": "prettier --write --ignore-path .gitignore \"**/*.{js,json,md,ts,vue,yml}\"",
    "prepare": "husky install"
  },
  "devDependencies": {
    "@formkit/i18n": "^0.17.5",
    "@nuxt/devtools": "^0.6.6",
    "@nuxt/image-edge": "1.0.0-28020728.5df24eb",
    "@nuxt/test-utils": "^3.6.5",
    "@nuxt/types": "^2.16.3",
    "@nuxtjs/i18n": "8.0.0-beta.12",
    "@nuxtjs/tailwindcss": "^6.6.6",
    "@storybook/addon-essentials": "^7.0.26",
    "@storybook/addon-interactions": "^7.0.26",
    "@storybook/addon-links": "^7.0.26",
    "@storybook/addon-styling": "^1.3.2",
    "@storybook/blocks": "^7.0.26",
    "@storybook/cli": "^7.0.26",
    "@storybook/testing-library": "^0.0.14-next.2",
    "@storybook/vue3": "^7.0.26",
    "@storybook/vue3-vite": "^7.0.26",
    "@types/country-list": "^2.1.1",
    "@vitejs/plugin-vue": "^4.2.3",
    "@vitest/coverage-v8": "^0.33.0",
    "@vitest/ui": "^0.33.0",
    "@vue/test-utils": "^2.4.1",
    "autoprefixer": "^10.4.14",
    "eslint-plugin-vitest": "^0.2.6",
    "happy-dom": "^10.6.3",
    "husky": ">=6",
    "jsdom": "^22.1.0",
    "lint-staged": ">=10",
    "nuxt": "^3.6.3",
    "nuxt-vitest": "^0.10.2",
    "postcss": "^8.4.24",
    "prettier": "^3.0.0",
    "prisma": "5",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "storybook": "^7.0.26",
    "storybook-addon-nuxt": "^1.3.3",
    "tailwindcss": "^3.3.2",
    "vitest": "^0.34.1"
  },
  "dependencies": {
    "@formkit/icons": "^0.17.5",
    "@formkit/nuxt": "^0.18.0-23c4d8f",
    "@formkit/themes": "^0.17.4",
    "@hapi/iron": "^7.0.1",
    "@nuxtjs/algolia": "^1.6.0",
    "@prisma/client": "5",
    "@stripe/stripe-js": "^1.52.1",
    "@types/marked": "^4.3.0",
    "algoliasearch": "^4.14.3",
    "country-list": "^2.3.0",
    "jose": "^4.14.4",
    "marked": "^4.3.0",
    "nuxt-icon": "^0.4.2",
    "postcss-custom-properties": "^13.2.0",
    "stripe": "^12.2.0"
  },
  "lint-staged": {
    "*.{js,css,md,vue,ts}": "prettier --write"
  }
}

Not sure what is happening. I read somewhere in the thread that it doesnt support cjs . But I am not sure if this is the issue and how to deal with it sadly.. Please advise..

Repository with easy reproduction : https://github.com/dtoxvanilla1991/nuxt-vitest-issue
Codesandbox reproduction fails when I try to import the demo app..sorry!
image

@uovol
Copy link

uovol commented Aug 3, 2023

I have the same problem.

I will return the version of vitest to 0.33.0 and it will be normal.

@oskarols
Copy link
Contributor

oskarols commented Aug 3, 2023

Afaik you should be importing the utils from nuxt-vitest/utils and not vitest-environment-nuxt/utils.

@rkorzhoff
Copy link

@oskarols I have the same problem even not importing the utils at all

@oskarols
Copy link
Contributor

oskarols commented Aug 4, 2023

Then the most likely culprit is that you're using v0.34 of Vitest. It seems they made some changes related to environments in that version. These changes seem to be breaking some portion of nuxt-vitest.

Try downgrading Vitest to 0.33.

@rkorzhoff
Copy link

@oskarols yep, it helped! Thanks!

@danielroe danielroe transferred this issue from danielroe/nuxt-vitest Dec 2, 2023
@danielroe
Copy link
Member

This has been resolved in the latest nightly release of @nuxt/test-utils and will be in the next release.

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

No branches or pull requests

5 participants