Error: Couldn't find preset “react” when installed using npm install --global babel-preset-react but works without global flag

后端 未结 2 1309
逝去的感伤
逝去的感伤 2021-01-01 18:25

I installed Babel CLI (version 6) using npm install --global babel-cli. I then install react preset using npm install --global babel-preset-react.

2条回答
  •  被撕碎了的回忆
    2021-01-01 19:16

    Optional Fix

    You can do it this way. Write these lines in your prompt. Now the only thing is with global you might have to use the fix suggested above by @Petar which is

    babel --presets /usr/local/lib/node_modules/babel-preset-react --watch jsx/ --out-dir js/
    

    but this one does all you need.

    npm i babel-cli babel-preset-react 
    
    babel --presets react jsx/ --watch --out-dir js/
    

    and Then optionally add a .gitignore file in your github repo with content = node_modules/ now run your jsx transformation with the same command.

提交回复
热议问题