sortablejs-vue3 icon indicating copy to clipboard operation
sortablejs-vue3 copied to clipboard

esm file must be of extension .mjs

Open said-m opened this issue 2 years ago • 1 comments

tldr: https://github.com/vuejs/vitepress/issues/1399#issuecomment-1258364648

hi, when component builds inside vitepress, it's fails with error:

✖ rendering pages...
build error:
 file:///Users/path-to-project/docs/.vitepress/.temp/SomeComponent.c214d190.js:4
import { Sortable } from "sortablejs-vue3";
         ^^^^^^^^
SyntaxError: Named export 'Sortable' not found. The requested module 'sortablejs-vue3' 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 'sortablejs-vue3';
const { Sortable } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

to handle such cases with different environments, need to change the extension of the file from .es.js to .es.mjs in package.json and vite.config of this project. checked locally with the this changes, project builds without errors and everything works

said-m avatar Jul 31 '23 10:07 said-m

@said-m can you create a PR for this change? I am using vitesse and get the same error

bgervan avatar Jan 02 '24 08:01 bgervan