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

'vue-demi' causes errors when importing (only the .mjs file breaks it) #1788

Closed
6 tasks done
dmix opened this issue Aug 4, 2022 · 3 comments
Closed
6 tasks done

'vue-demi' causes errors when importing (only the .mjs file breaks it) #1788

dmix opened this issue Aug 4, 2022 · 3 comments

Comments

@dmix
Copy link

dmix commented Aug 4, 2022

Describe the bug

I get this error whenever I import a Pinia store into my test:

SyntaxError: The requested module 'vue-demi' does not provide an export named 'computed'
 ❯ ../../async /Users/dmix/dev/callpixels/app/javascript/__tests__/stores/target_options_test.ts:1:256

Also got a more detailed version with some tweaks:

SyntaxError: Named export 'computed' not found. The requested module 'vue-demi' 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 'vue-demi';
const { getCurrentInstance, inject, toRaw, watch, unref, markRaw, effectScope, ref, isVue2, isRef, isReactive, set, onUnmounted, reactive, toRef, del, nextTick, computed, toRefs } = pkg;

 ❯ ../../async /Users/dmix/dev/callpixels/app/javascript/__tests__/stores/target_options_test.ts:1:256

This is the code in the test file (removing pinia stuff resolves the error)

import { setActivePinia, createPinia } from 'pinia'
import {
    useTargetOptionStore,
    TargetOptionState,
} from '../../stores/target_options'

describe('TargetOption Store', function() {
    beforeEach(() => {
        setActivePinia(createPinia())
        store = useTargetOptionStore()
    })
    ...

This is not a new issue, others have managed to solve it by explicitly add .mjs settings to webpack:

vueuse/vueuse#718 (comment)

The problem is that I'm using Vite and not webpack, so I dont know how to apply a similar config setting.

I resolved the issue by simply deleting the .mjs file rm ./node_modules/pinia/dist/pinia.mjs, this is fine because there's also the exact same .js version of this file

Is there a way to fix this mjs issue?

Reproduction

My full vite.config.ts file:

https://gist.github.com/dmix/780c81495d3fdfdf140e7cbe1e95e4c0

System Info

MacOS

Used Package Manager

yarn

Validations

@github-actions
Copy link

github-actions bot commented Aug 4, 2022

Hello @dmix. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@sheremet-va
Copy link
Member

You can disable this behaviour with test.deps.registerNodeLoader: false for now.

@dmix
Copy link
Author

dmix commented Aug 4, 2022

@sheremet-va thanks but that didnt seem to stop the error:

I added this to my vite.config.ts:

    test: {
        globals: true,
        environment: 'jsdom',
        include: ['__tests__/**/*_{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
        deps: {
          registerNodeLoader: false,
        }
    },

@github-actions github-actions bot closed this as completed Aug 8, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants