GithubHelp home page GithubHelp logo

ma125120 / cjs2esmodule Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 5.0 46 KB

将commonjs转为es module,可在vite中使用,也可直接转换文件

License: MIT License

TypeScript 32.80% JavaScript 66.56% Shell 0.64%

cjs2esmodule's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cjs2esmodule's Issues

[bug]语法转换错误

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
}

[bug]没有 /lib/index.js 文件

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 的时候出错了?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.