Couldn't find preset “env” relative to directory

夙愿已清 提交于 2019-12-06 17:04:17

问题


So far I have been unsuccessful in an attempt to use the env preset. I browsed the git issues that others have raised such as this, and implemented some of the suggestions that appeared to work for others, but no luck so far.

Here's what I'm working with:

package.json

"bundle": "browserify ./client/app.js -d -o ./public/o.js -t [ babelify --presets [ env ] ]",
"devDependencies": {
  "@babel/cli": "^7.0.0-beta.40",
  "@babel/preset-env": "^7.0.0-beta.40",
  "babel-core": "^6.26.0",
  "babelify": "^8.0.0"
...

And here is the error:

Error: Couldn't find preset "env" relative to directory "/Users/user/Documents/git/ts/client" while parsing file: /Users/user/Documents/git/ts/client/app.js

Anything I could be missing?


回答1:


Many of the github issues relating to this suggest that babel-preset-env is not installed.

Indeed it doesn't seem to be there in your package.json. Add & install it by doing this:

npm install babel-preset-env --save




回答2:


You just need to install babel-preset-env and your code will compile properly.

npm install babel-preset-env




回答3:


Though the earlier answers do provide the right solution and it works. But this should be installed as a dev dependency not as the core one. As this is needed only for development work. If you are using npm you can use:

npm install --save-dev babel-preset-env

or if you are using yarn as package manager then use:

yarn add --dev babel-preset-env



来源:https://stackoverflow.com/questions/48848249/couldnt-find-preset-env-relative-to-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!