我在全局安装了一个babel-cli,使用bable-node的是否出现了一个globals的错误

MrXu
  • 80
// a.js
module.exports = 'a';

// index.js
import a from './a'

console.log(a);

// .babelc
{
  "presets": [
    ["env", {
      "targets": {
        "node": "current"
      }
    }]
  ]
}

使用以下语句执行:

babel-node index.js

出现了如下的错误:

/usr/local/lib/node_modules/babel-cli/node_modules/_babel-core@6.26.3@babel-core/lib/transformation/file/options/option-manager.js:328
        throw e;
        ^

Error: Cannot find module 'globals' (While processing preset: "/Users/xuyuechao/Work/other-git-project/babel/node_modules/_babel-preset-env@1.7.0@babel-preset-env/lib/index.js")
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/xuyuechao/Work/other-git-project/babel/node_modules/_babel-traverse@6.26.0@babel-traverse/lib/scope/index.js:53:16)
    at Module._compile (module.js:652:30)
    at Module._extensions..js (module.js:663:10)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel-cli/node_modules/_babel-register@6.26.0@babel-register/lib/node.js:152:7)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
回复
阅读 1.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏