2016-07-06 99 views
3

我已經按照不同的開發者發佈的stackoverflow帖子上的解決方案。但是,他們都沒有幫助解決我遇到的問題。少數人的事情,我確實是Webpack與巴貝爾失敗已被轉移到巴貝爾核心

  1. 卸載通天
  2. 安裝通天核心,巴貝爾-CLI
  3. 升級爲節點V6.2.2
  4. 重裝的WebPack
  5. 炸燬了node_modules就跑NPM安裝再次

上述所有的永遠定格這個錯誤

ERROR in The node API for `babel` has been moved to `babel-core`. 
@ (webpack)-dev-server/client?http://localhost:3333 1:10-24 

ERROR in The node API for `babel` has been moved to `babel-core`. 
@ (webpack)-dev-server/client?http://localhost:3333 3:16-37 

ERROR in The node API for `babel` has been moved to `babel-core`. 
@ (webpack)-dev-server/client?http://localhost:3333 2:13-37 

ERROR in (webpack)/~/process/browser.js 
Module build failed: Error: Couldn't find preset "react" relative to directory "/Users/admin/.nvm/versions/node/v6.0.0/lib/node_modules/webpack/node_modules/process" 
    at /Users/admin/repos/ReactJSApps/react-es6-setup/node_modules/babel-core/lib/transformation/file/options/option-manager.js:395:17 
    at Array.map (native) 
. 
. 
. 
webpack: bundle is now VALID. 

這裏是我的package.json

{ 
    "name": "react-es6-setup", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "start": "webpack-dev-server" 
    }, 
    "author": "", 
    "license": "ISC", 
    "dependencies": { 
    "react": "^15.2.0", 
    "react-dom": "^15.2.0" 
    }, 
    "devDependencies": { 
    "babel-core": "^6.10.4", 
    "babel-loader": "^6.2.4", 
    "babel-preset-es2015": "^6.9.0", 
    "babel-preset-react": "^6.11.1" 
    } 
} 

而且webpack.config.js

module.exports = { 
    entry: './main.js', 
    output: { 
    path: './', 
    filename: 'index.js' 
    }, 
    devServer: { 
    inline: true, 
    port: 3333 
    }, 
    module: { 
    loaders: [ 
     { 
      test: /\.js$/, 
      exclude: 'node_modules', 
      loader: 'babel', 
      query: { 
      presets: [ 'es2015', 'react' ] 
      } 
     } 
    ] 
    } 
} 

和node_modules的DIR上市

$ ls -l node_modules/ |grep react 
drwxr-xr-x 6 admim 207825898 204 Jul 6 02:02 babel-helper-builder-react-jsx/ 
drwxr-xr-x 6 admim 207825898 204 Jul 6 02:02 babel-plugin-transform-react-display-name/ 
drwxr-xr-x 6 admim 207825898 204 Jul 6 02:02 babel-plugin-transform-react-jsx/ 
drwxr-xr-x 6 admim 207825898 204 Jul 6 02:02 babel-plugin-transform-react-jsx-self/ 
drwxr-xr-x 6 admim 207825898 204 Jul 6 02:02 babel-plugin-transform-react-jsx-source/ 
drwxr-xr-x 6 admim 207825898 204 Jul 6 02:02 babel-preset-react/ 
drwxr-xr-x 9 admim 207825898 306 Jul 6 02:03 react/ 
drwxr-xr-x 9 admim 207825898 306 Jul 6 02:03 react-dom/ 
+0

我沒有看到的WebPack在你的package.json,你安裝它沒有NPM,或全球? –

+0

我全局安裝了它。這是我做的,它修復了它。我卸載了它,並沒有再使用-g。我剛剛添加了--save-dev。有什麼不同? – devwannabe

+1

我的第一個想法是,您使用的是舊版本的webpack,所以我想查看package.json中的版本並注意到它不在那裏。我不確定它爲什麼現在能夠正常工作,除非您使用的以前版本有問題。很高興它是固定的! –

回答

0

試試這個:

First del ETE的node_module文件夾,然後

npm init 
npm i webpack -S (Install Globally too) 
npm i babel-loader babel-preset-es2015 babel-preset-react babel-core -S 
npm i react react-dom -S` 

確保您webpack.config.js有:

loaders: [ 
    { 
     test: /\.js$/, 
     exclude: 'node_modules', 
     loader : 'babel-loader', 

... 

然後run webpack -d

5

具有webpack.config.jsloaders: 'babel-loader'固定的問題,我 -

使用npm安裝這些依賴項

"babel-core": "^6.1.2", 
"babel-loader": "^6.1.0", 
"babel-plugin-transform-runtime": "^6.1.2", 
"babel-preset-es2015": "^6.1.2", 
"babel-preset-stage-0": "^6.1.2", 
"babel-runtime": "^5.8.0", 

webpack.config.js文件中,有這樣的代碼:

const path = require('path'); 
module.exports = { 
    entry: './src/main.js', 
    output: { 
    path: path.resolve(__dirname, 'dist'), 
    filename: 'dist.js', 
    publicPath: "js" 
    }, 
    module: { 
    loaders: [ 
     { 
     test: /\.js$/, 
     loader: 'babel-loader', 
     exclude: /node_modules/ 
     } 
    ] 
    } 
}