echarts icon indicating copy to clipboard operation
echarts copied to clipboard

vue中 import 失败

Open hans007 opened this issue 9 years ago • 7 comments

One-line summary [问题简述]

./src/main.js 文件中

import echarts from 'echarts'

执行 npm start

提示错误

 WARNING  Compiled with 1 warnings           
                                                                                                
 warning  in ./src/main.js

6:25-32 "export 'default' (imported as 'echarts') was not found in 'echarts'

> Listening at http://localhost:8080

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]: 3.8.0

  • Browser version [浏览器类型和版本]: node v8.9.1 npm v5.5.1

  • OS Version [操作系统类型和版本]:

Expected behaviour [期望结果]

ECharts option [ECharts配置项]

option = {

}

Other comments [其他信息]

hans007 avatar Nov 09 '17 03:11 hans007

使用 import * as echarts from 'echarts';

quapyrus avatar Nov 09 '17 04:11 quapyrus

上一秒还是 3.7.2,用的是 CommonJS 模块。下一秒就换 3.8.0,用 es6 模块了。被坑了。。。而且还有 __DEV__ 这种问题

quapyrus avatar Nov 09 '17 05:11 quapyrus

  • package.json 我换成了
    "echarts": "^3.7.2",
  • src/man.js
import echarts from 'echarts'
  • npm start console 显示错误
Uncaught ReferenceError: __DEV__ is not defined
    at Function.RootClass.extend (clazz.js?7b97:66)
    at eval (webpack-internal:///12:29)
    at Object.<anonymous> (app.js:817)
    at __webpack_require__ (app.js:679)
    at fn (app.js:89)
    at eval (webpack-internal:///215:4)
    at Object.<anonymous> (app.js:2215)
    at __webpack_require__ (app.js:679)
    at fn (app.js:89)
    at Object.eval (echarts.js?548c:1)

hans007 avatar Nov 09 '17 05:11 hans007

@hans007 去掉"^", 这个符号会导致npm默认install最新的minor version的echarts, 即3.x.x, 去掉"^"锁定版本即可。

evagy avatar Nov 09 '17 05:11 evagy

问题已解决,我是 vue2 的项目

编辑 build/webpack.base.conf.js

var webpack = require("webpack")

......

  plugins: [
    new webpack.DefinePlugin({
      __DEV__: false
    })
  ],

然后我再运行,就没问题了~~~~ 感谢 @quapyrus @YuyangGong

hans007 avatar Nov 09 '17 05:11 hans007

Hi there, (Sorry I cannot write in Chinese)

This issue seems to have happened already ( look at issue #6535 ). This was the fix they pushed : https://github.com/tangdaohai/echarts/commit/bddaa80deb32fe75b448b47f603b7d0b0f414b63.

But I don't see the devs change all snippets if (__DEV__) {} into if (typeof __DEV__ !== 'undefined' && __DEV__) {}. There are too many of them..

ps: seems related to #6111 too.

darkurse avatar Nov 09 '17 09:11 darkurse

@hans007 铁,你是咋解决的啊。。我跟你是一样的项目和问题,求教,感谢

bxychy avatar Nov 09 '17 10:11 bxychy