Webpack React.createElement:类型无效 - 期望一个字符串?

时间:2018-03-29 09:48:26

标签: reactjs webpack babel

这门课有什么问题?

import React from 'react'

export default class Test extends React.Component {
  render() {
    return <h2>test</h2>
  }
}

肯定没错,但我得错误

React.createElement: type is invalid — expected a string 之后我用webpack和babel进行了编译。

我在尝试使用这样的编译版本时遇到错误 import Test from '../lib/test.js'

我的webpack配置如下

const path = require('path');
const webpack = require('webpack');

module.exports = {

    entry: {
        'test': path.resolve(__dirname, 'src') + '/test.js',
    },
    output: {
        path: path.resolve(__dirname, 'lib'),
        filename: '[name].js',
    },
    module: {
        rules: [
            {
                test: /.js[x]?$/,
                include: path.resolve(__dirname, 'src'),
                exclude: path.resolve(__dirname, 'node_modules'),
                use: 'babel-loader',
            },
            {
              test: /\.scss|css$/,
              use: [
                'style-loader',
                'css-loader',
                'sass-loader'
              ]
            },
            {
                test: /\.(eot|woff|woff2|ttf|svg|ico|png|jpe?g|gif)$/,
                use: ['file-loader?name=[name].[ext]&outputPath=assets/images/',
                      'image-webpack-loader']
            },
        ]
    },
    plugins: [
        new webpack.NamedModulesPlugin()
    ]
};

可能这是个问题吗?我的.babelrc

 {
    "presets": ["es2015", "react"],
    "plugins": [
        ["transform-class-properties", { "spec": true }]
      ]
}

0 个答案:

没有答案