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

v0.12.0 import mjs issue #106

Closed
sxzz opened this issue Oct 9, 2021 · 10 comments
Closed

v0.12.0 import mjs issue #106

sxzz opened this issue Oct 9, 2021 · 10 comments

Comments

@sxzz
Copy link
Member

sxzz commented Oct 9, 2021

I upgrade @vue/composition-api from 1.1.5 to 1.2.4, and it emit error.

Error: [vue-composition-api] must call Vue.use(VueCompositionAPI) before using any function

I checked it babel jsx plugin imported @vue/composition-api/dist/vue-composition-api.mjs, but vue-demi imported @vue/composition-api/dist/vue-composition-api.esm.js.

So I think it should be changed to .mjs as well.

https://github.com/vuejs/composition-api/blob/a5a68e0e35321bf9d508c0a3046560112579de9b/package.json#L20

import VueCompositionAPI from '@vue/composition-api/dist/vue-composition-api.esm.js'

@sxzz sxzz mentioned this issue Oct 9, 2021
@sxzz
Copy link
Member Author

sxzz commented Oct 9, 2021

solution: #105 (comment)

@Shinigami92
Copy link

Current workaround for me is

// package.json
// ...
  "resolutions": {
    "vue-demi": "0.11.4"
  }
// ...

@antfu
Copy link
Member

antfu commented Oct 27, 2021

You better set the alias for future-proofing:

{
  alias: {
    '@vue/composition-api': '@vue/composition-api/dist/vue-composition-api.mjs',
    '@vue/composition-api/dist/vue-composition-api.esm.js': '@vue/composition-api/dist/vue-composition-api.mjs'
  }
}

@Shinigami92
Copy link

Getting this error:

[vite:load-fallback] Could not load @vue/composition-api/dist/vue-composition-api.mjs/dist/vue-composition-api.mjs (imported by node_modules/vue-demi/lib/index.mjs): ENOENT: no such file or directory, open '@vue/composition-api/dist/vue-composition-api.mjs/dist/vue-composition-api.mjs'
error during build:
Error: Could not load @vue/composition-api/dist/vue-composition-api.mjs/dist/vue-composition-api.mjs (imported by node_modules/vue-demi/lib/index.mjs): ENOENT: no such file or directory, open '@vue/composition-api/dist/vue-composition-api.mjs/dist/vue-composition-api.mjs'

My vite.config.ts is:

import { resolve } from 'path';
import { defineConfig } from 'vite';
import tsNameof from 'vite-plugin-ts-nameof';
import { createVuePlugin } from 'vite-plugin-vue2';

// https://vitejs.dev/config
export default defineConfig({
  plugins: [
    tsNameof(),
    createVuePlugin()
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, './src'),

      // https://github.com/vueuse/vue-demi/issues/106#issuecomment-953155139
      '@vue/composition-api': '@vue/composition-api/dist/vue-composition-api.mjs',
      '@vue/composition-api/dist/vue-composition-api.esm.js': '@vue/composition-api/dist/vue-composition-api.mjs'
    }
  },
  build: {
    assetsDir: 'static',
    target: ['chrome63'],
    chunkSizeWarningLimit: 2048
  },
  server: {
    port: 18080
  }
});

Using resolve for these aliases also doesn't work and result in same error

@sxzz
Copy link
Member Author

sxzz commented Oct 28, 2021

@vue/composition-api/dist/vue-composition-api.mjs
transformed to
@vue/composition-api/dist/vue-composition-api.mjs/dist/vue-composition-api.mjs

Because of '@vue/composition-api': '@vue/composition-api/dist/vue-composition-api.mjs'.

Try to use regexp

alias: [
  { find: /^@vue\/composition-api$/, replacement: '@vue/composition-api/dist/vue-composition-api.mjs' },
]

@Shinigami92
Copy link

@sxzz Thank you, that works:

  resolve: {
    alias: [
      { find: '@', replacement: resolve(__dirname, './src') },
      { find: /^@vue\/composition-api$/, replacement: '@vue/composition-api/dist/vue-composition-api.mjs' }
    ]
  }

@sxzz
Copy link
Member Author

sxzz commented Oct 28, 2021

Fixed in #105

@antfu
Copy link
Member

antfu commented Oct 28, 2021

Now in @vue/composition-api v1.3.0, it should export .mjs by default. If everything works correctly you might no longer need the alias. See https://github.com/vuejs/composition-api/releases/tag/v1.3.0 for more details.

@Shinigami92
Copy link

Can confirm it works 🎉

@Demivan
Copy link
Contributor

Demivan commented Dec 13, 2021

@antfu, I think it would be a good idea to update @vue/composition-api peer-dependency range to be "^1.3.0". This way you should get a warning when using a non mjs-ready @vue/composition-api version.

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

Successfully merging a pull request may close this issue.

4 participants