设置babel后,为什么我的代码抛出该错误?

时间:2019-02-14 02:10:46

标签: javascript webpack babel

设置Babel后出现错误。我知道我的babel loader版本是8,而babel-core是6,这可能是问题之一。我试图下载模块'@ babel / core'或什至是babel loader的版本7,但仍然给我错误..如何解决该问题???

这些都是我在运行npm run dev时遇到的所有错误

ERROR in ./src/js/index.js
    Module build failed (from ./node_modules/babel-loader/lib/index.js):
    Error: Cannot find module '@babel/core'
     babel-loader@8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
        at Function.Module._load (internal/modules/cjs/loader.js:507:25)
        at Module.require (internal/modules/cjs/loader.js:637:17)
        at require (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
        at Object.<anonymous> (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/babel-loader/lib/index.js:10:11)
        at Module._compile (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
        at Module.load (internal/modules/cjs/loader.js:599:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
        at Function.Module._load (internal/modules/cjs/loader.js:530:3)
        at Module.require (internal/modules/cjs/loader.js:637:17)
        at require (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
        at loadLoader (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/loader-runner/lib/loadLoader.js:18:17)
        at iteratePitchingLoaders (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
        at runLoaders (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/loader-runner/lib/LoaderRunner.js:365:2)
        at NormalModule.doBuild (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/webpack/lib/NormalModule.js:280:3)
        at NormalModule.build (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/webpack/lib/NormalModule.js:427:15)
        at Compilation.buildModule (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/webpack/lib/Compilation.js:635:10)
        at factory.create (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/webpack/lib/Compilation.js:884:14)
        at factory (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/webpack/lib/NormalModuleFactory.js:405:6)
        at hooks.afterResolve.callAsync (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/webpack/lib/NormalModuleFactory.js:155:13)
        at AsyncSeriesWaterfallHook.eval [as callAsync] (eval at create (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
        at resolver (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/webpack/lib/NormalModuleFactory.js:138:29)
        at process.nextTick (/Users/sandrahelicka/Desktop/RecipeFinder/node_modules/webpack/lib/NormalModuleFactory.js:342:9)
        at process._tickCallback (internal/process/next_tick.js:61:11)
     @ multi babel-polyfill ./src/js/index.js main[1]
    Child html-webpack-plugin for "index.html":
         1 asset
        Entrypoint undefined = index.html
        [./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html] 18.2 KiB {0} [built]
        [./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 472 bytes {0} [built]
        [./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 497 bytes {0} [built]
            + 1 hidden module
    npm ERR! code ELIFECYCLE
    npm ERR! errno 2
    npm ERR! recipefinder@1.0.0 dev: `webpack --mode development`
    npm ERR! Exit status 2
    npm ERR! 
    npm ERR! Failed at the recipefinder@1.0.0 dev script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

0 个答案:

没有答案