【问题标题】:Webpack: Bundle.js - Uncaught TypeError: (intermediate value).setTimeout is not a functionWebpack:Bundle.js - 未捕获类型错误:(中间值).setTimeout 不是函数
【发布时间】:2017-05-12 14:45:42
【问题描述】:

这是我的 webpack.config.js

 "use strict";
var webpack = require('webpack')

module.exports = {
    entry: ['./main.js'],
    output: { path: __dirname, filename: 'bundle.js' },
    module: {
        loaders: [
            {
                test: /.js?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    presets: ['es2015', 'react']
                }
            },
            {test: /\.json$/, loader: "json"},
        ]
    },
    externals: {
        React: 'react',
    },
    target: "node",
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify('development'),
            'global': {},
        })
    ],
};

还有 Main.js

import React from 'react';
import ReactDOM from 'react-dom';
import {Table, Column, Cell} from 'fixed-data-table';
import Chart from 'chartjs';
import jQuery from 'jquery';
import vis from 'vis';
import babel from 'babel-core';

Bundle.js 被插入到我的 Index.html 中。然后浏览器给出错误:

Uncaught TypeError: (intermediate value).setTimeout is not a function
    at requestAnimationFrame (bundle.js:21935)
    at Object.<anonymous> (bundle.js:21941)
    at __webpack_require__ (bundle.js:20)
    at Object.<anonymous> (bundle.js:21187)
    at __webpack_require__ (bundle.js:20)
    at Object.<anonymous> (bundle.js:20136)
    at __webpack_require__ (bundle.js:20)
    at Object.<anonymous> (bundle.js:19602)
    at __webpack_require__ (bundle.js:20)
    at Object.<anonymous> (bundle.js:19553)

此错误的原因是什么,如何更改 webpack 配置以使其消失?

【问题讨论】:

    标签: javascript node.js webpack


    【解决方案1】:

    我通过在 webpack 配置中将 global 定义为插件来解决它,输入为空。

    'global': {},

    【讨论】:

    • 你的意思是在DefinePlugin里面?
    • 在 webpack.config,js 中哪里会定义这一行? @cbll
    【解决方案2】:

    在 Gulp 中的 Babelify 之后使用 uglify() 解决。

    例子:

    .transform(babelify.configure({presets: ['@babel/preset-env']}))
    .bundle() .pipe(source('app.js')) .pipe(buffer()) .pipe(uglify())
    

    【讨论】:

      猜你喜欢
      • 2016-08-20
      • 2022-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-06
      • 2019-05-24
      • 2021-12-15
      相关资源
      最近更新 更多