ma125120 / cjs2esmodule Goto Github PK
View Code? Open in Web Editor NEW将commonjs转为es module,可在vite中使用,也可直接转换文件
License: MIT License
将commonjs转为es module,可在vite中使用,也可直接转换文件
License: MIT License
1.问题描述:
当module.exports作为一个值赋予给一个变量的时候会出现转换错误.
2.复现
源代码:
var meta = module.exports = {
enable: enable,
fastKey: fastKey,
getWeakData: getWeakData,
onFreeze: onFreeze
};
转换后: 这里的var并没有被替换掉.
{
code: 'var export default {\n' +
' enable: enable,\n' +
' fastKey: fastKey,\n' +
' getWeakData: getWeakData,\n' +
' onFreeze: onFreeze\n' +
'};;',
map: null,
rawMappings: undefined
}
3.期望
export default {
enable: enable,
fastKey: fastKey,
getWeakData: getWeakData,
onFreeze: onFreeze
}
1.1.0 版本,通过 yarn 安装的。
Error: Cannot find module '/Users/xxx/Desktop/vite-demo/node_modules/cjs2esmodule/lib/index.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (internal/modules/cjs/loader.js:303:19)
at Function.Module._findPath (internal/modules/cjs/loader.js:516:18)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/Users/liujun/Desktop/vite-demo/vite.config.js:31:38)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.require.extensions.<computed> [as .js] (/Users/liujun/Desktop/vite-demo/node_modules/vite/dist/node/chunks/dep-efe32886.js:46235:20)
at Module.load (internal/modules/cjs/loader.js:928:32)
error Command failed with exit code 1.
是不是构建发布 npm 的时候出错了?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.