首页 > 解决方案 > TypeError: Object(...) is not a function uuid in reactjs and webpack

问题描述

我正在使用带有 webpack 4 的 reactjs 并收到此消息: TypeError: Object(...) is not a function

应用程序.js:

import { v4 as uuidv4 } from 'uuid';
console.log(uuidv4());

.babelrc:

{
    "presets": ["@babel/preset-env", "@babel/preset-react"],
    "plugins": ["@babel/plugin-transform-runtime"]
}

webpack.common.js

const path = require('path');

module.exports = {
    entry: {
        app: './src/index.jsx'
    },
    module: {
        rules: [
            {
                test: /\.js|jsx$/,
                exclude: /node_modules/,
                use: 'babel-loader'
            },
            {
                test: /\.png|jpe?g|gif|ttf|woff|woff2|eot|svg$/,
                use: [
                    {
                        loader: 'file-loader'
                    }
                ]
            }
        ]
    },
    resolve: {
        extensions: ['.js', '.jsx']
    },
    output: {
        filename: 'js/[name].[chunkhash].js',
        chunkFilename: 'js/[name].[chunkhash].js',
        path: path.resolve(__dirname, 'dist'),
        publicPath: '/'
    },
    ..........
};

标签: reactjswebpackuuid

解决方案


推荐阅读