小编kas*_*sia的帖子

Babel、Jest 和 webpack 的“语法错误:无法在模块外使用导入语句”

我对 Babel 7、Webpack 4 和 Jest 的配置有问题。当我运行测试时,我收到以下错误:

语法错误:不能在模块外使用导入语句

包.json

 "@babel/core": "^7.7.5",
    "@babel/highlight": "^7.8.3",
    "@babel/plugin-syntax-dynamic-import": "^7.8.3",
    "@babel/preset-env": "^7.8.4",
    "babel-core": "^7.0.0-bridge.0",
    "babel-loader": "^7.1.5",
    "@babel/plugin-transform-runtime": "^7.7.4",
    "@babel/preset-react": "^7.7.4",
    "@babel/runtime": "^7.8.4",
    "babel-jest": "^24.9.0",
    "jest-watch-typeahead": "^0.4.2",
    "vue-jest": "^3.0.5",
    "jest": "^24.9.0",
    "jest-serializer-vue": "^2.0.2",
    "jest-transform-stub": "^2.0.0",
Run Code Online (Sandbox Code Playgroud)

webpack.config.js

  entry: {
      app: ["./src/index.js"]
  },
  output: {
    path: path.resolve('../', 'static/js/'), 
    filename: "[name].js",
    publicPath: '/static/js/', 
    chunkFilename: '[name].chunk.js' 
  }, 
Run Code Online (Sandbox Code Playgroud)

.babelrc - 我认为问题出在 module: false 但如果我不包含它,webpack 不会分块我的文件。


{
  "presets": [
    ["@babel/preset-env", {"modules": false}, "jest" ]
  ],
  "plugins": [
    "@babel/plugin-syntax-dynamic-import" 
  ],
    "env": {  
      "test": …
Run Code Online (Sandbox Code Playgroud)

webpack jestjs babeljs

5
推荐指数
1
解决办法
1万
查看次数

D3更新条形图VUE.js

嘿,我在 Vue 中使用 d3 图表时遇到问题。除了更新数据之外,一切都加载正常。

我使用 props 来传递数据,当数据更改我的图表而不是更新时,它会在当前图表下方创建另一个图表。

我想要做的是保留当前图表并在数据变化时仅更新条形图

<script>
export default {
    props: {
      arr: {
          type: Array
      }, 
      colors: {
          type: Array
      }
  },
  watch: {
    arr: {
      immediate: true,
      handler(val) {
        setTimeout(() => {
          this.barCharts(val)
        }, 100);
      }
    }
  },
  methods: {
    barCharts(data) {
      let margin = { top: 40, right: 20, bottom: 50, left: 60 };
      let width = 650
      let height = 240; 

      let color = d3.scaleOrdinal().range(this.colors);
      let t = d3.transition().duration(750);

      let g = d3 …
Run Code Online (Sandbox Code Playgroud)

methods data-visualization bar-chart d3.js vue.js

2
推荐指数
1
解决办法
1650
查看次数