vuejs / vue-class-component

ES / TypeScript decorator for class-style Vue components.
MIT License
5.81k stars 429 forks source link

build!: use cjs/mjs extensions for cjs/esm builds #571

Open danielroe opened 2 years ago

danielroe commented 2 years ago

Summary

This PR proposes using .cjs and .mjs instead of the current .common.js and .esm.js extensions. That allows usage of this library in a native Node module context.

Notes

Background issue

At the moment, importing vue-class-component within an ESM context produces the following error:

/project/node_modules/vue-class-component/dist/vue-class-component.esm-bundler.js:6
import { ref, proxyRefs } from 'vue';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:169:25)
    at async Loader.import (internal/modules/esm/loader.js:177:24)
    at async __instantiateModule__ (file:///project/.nuxt/dist/server/server.mjs:2180:3)

see https://github.com/nuxt/nuxt.js/issues/12050 closes nuxt/bridge#289