node - 关于babel-loader的问题

查看:318
本文介绍了node - 关于babel-loader的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

我在运行Vue项目时,提示以下报错信息
不知道是否是因为babel的版本问题,到解析 Promise 的时候就报错了,有谁知道帮忙解答一下,十分感谢

ERROR in ./~/.npminstall/babel-loader/6.2.5/babel-loader!./~/.npminstall/vue-loader/9.7.0/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue
Module not found: Error: Cannot resolve module 'babel-runtime/helpers/extends' in /Users/st/work/vue/Vuex-maizuo/src
 @ ./~/.npminstall/babel-loader/6.2.5/babel-loader!./~/.npminstall/vue-loader/9.7.0/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue 7:16-56

ERROR in ./~/.npminstall/babel-loader/6.2.5/babel-loader!./~/.npminstall/vue-loader/9.7.0/vue-loader/lib/selector.js?type=script&index=0!./src/views/home/index.vue
Module not found: Error: Cannot resolve module 'babel-runtime/helpers/extends' in /Users/st/work/vue/Vuex-maizuo/src/views/home
 @ ./~/.npminstall/babel-loader/6.2.5/babel-loader!./~/.npminstall/vue-loader/9.7.0/vue-loader/lib/selector.js?type=script&index=0!./src/views/home/index.vue 7:16-56

ERROR in ./src/vuex/modules/film/mutations.js
Module not found: Error: Cannot resolve module 'babel-runtime/helpers/defineProperty' in /Users/st/work/vue/Vuex-maizuo/src/vuex/modules/film
 @ ./src/vuex/modules/film/mutations.js 7:23-70

ERROR in ./src/vuex/modules/app/mutations.js
Module not found: Error: Cannot resolve module 'babel-runtime/helpers/defineProperty' in /Users/st/work/vue/Vuex-maizuo/src/vuex/modules/app
 @ ./src/vuex/modules/app/mutations.js 7:23-70

ERROR in ./src/vuex/modules/film/actions.js
Module not found: Error: Cannot resolve module 'babel-runtime/core-js/promise' in /Users/st/work/vue/Vuex-maizuo/src/vuex/modules/film
 @ ./src/vuex/modules/film/actions.js 8:15-55

.babelrc

{
  "presets": ["es2015", "stage-2"],
  "plugins": ["transform-runtime"],
  "comments": false
}

只引用一个模块也报错

ERROR in ./src/vuex/modules/film/actions.js
Module not found: Error: Cannot resolve module 'babel-runtime/core-js/promise' in /Users/lt/work/vue/Vuex-maizuo/src/vuex/modules/film
 @ ./src/vuex/modules/film/actions.js 8:15-55

main.js

import 'babel-polyfill'
import Vue from 'vue'
import VueRouter from 'vue-router'
import VueResour from 'vue-resource'
import FastClick from 'fastclick'
// import routerConfig from './routers'
import store from './vuex/store'
// // import App from './App'
//
// Vue.use(VueRouter)
// Vue.use(VueResource)
// const router = new VueRouter({routes: routerConfig})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  // router,
  // store,
  // render: h => h(App),
});
//
// window.addEventListener('load', ()=>{
//   FastClick.attach(document.body)
// })

报错的模块actions.js

import Vue from 'vue'

/**
 * [_get 异步获取数据公共方法]
 * @param  {[String]} options.url    [api地址]
 * @param  {[String]} options.query  [查询参数]
 * @return {[Promise]}        [Promise]
 */
const _get = ({url, query}, commit) => {
  if(commit) commit('START_LOADING')

  let _url
  if(query){
    _url =  `http://m.maizuo.com/v4/api${url}?${query}`
  } else {
    _url = `http://m.maizuo.com/v4/api${url}`
  }

  return Vue.http.get(_url)
    .then((res)=>{
      if( commit ) commit('FINISH_LOADING')
      if(res.status >= 200 && res.status < 300){
        return res.data
      }
      return Promise.reject(new Error(res.status))
    })
}

promis这个模块是有的

完整代码
https://github.com/git-lt/Vue...

解决方案

https://github.com/babel/babe...

你需要安装多一个 babel-runtime

npm install babel-runtime --save

这篇关于node - 关于babel-loader的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆