标签归档:babel
Error: Couldn’t find preset “es2015” relative to directory
问题
使用babel转换代码时报如下错误:
1 2 3 4 5 6 7 8 9 10 11 12 |
PS H:\project\nodejs\demo\learn\chapter3\3.11> babel .\test.js Error: Couldn't find preset "es2015" relative to directory "H:\\project\\nodejs\\demo\\learn" at G:\dev\nvm\v14.17.4\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:293:19 at Array.map (<anonymous>) at OptionManager.resolvePresets (G:\dev\nvm\v14.17.4\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:275:20) at OptionManager.mergePresets (G:\dev\nvm\v14.17.4\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:264:10) at OptionManager.mergeOptions (G:\dev\nvm\v14.17.4\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:249:14) at OptionManager.init (G:\dev\nvm\v14.17.4\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12) at File.initOptions (G:\dev\nvm\v14.17.4\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\index.js:212:65) at new File (G:\dev\nvm\v14.17.4\node_modules\babel-cli\node_modules\babel-core\lib\transformation\file\index.js:135:24) at Pipeline.transform (G:\dev\nvm\v14.17.4\node_modules\babel-cli\node_modules\babel-core\lib\transformation\pipeline.js:46:16) at transform (G:\dev\nvm\v14.17.4\node_modules\babel-cli\lib\babel\util.js:50:22) |
1 2 3 4 |
.babelrc配置 { "presets": ["es2015", "stage-0"] } |
解决
安装 ES 标准
1 |
npm i -D babel-preset-es2015 |
再次运行
1 2 3 4 5 6 |
PS H:\project\nodejs\demo\learn\chapter3\3.11> babel .\test.js "use strict"; var a = 1, b = 2, c = 3; |