npm запустить сборку (Ошибка разбора модуля) - PullRequest
0 голосов
/ 22 апреля 2020

Я довольно новичок в React и пытаюсь настроить модуль npm. На этапе npm run build он продолжает давать сбой, и я не уверен, что на самом деле вызывает проблему. Я смотрел на другие ответы, относящиеся к 'babel-loader', но мой выглядит хорошо в соответствии с этими ответами.

Ошибка:

> webpack && npm run cleancss

Hash: 4faa93666033a0f17524
Version: webpack 3.12.0
Time: 76ms
 2 assets
   [0] ./src/index.js 291 bytes {0} [built]
   [1] (webpack)/buildin/harmony-module.js 596 bytes {0} [built]
   [2] ./src/SideNav.jsx 245 bytes {0} [built] [failed] [1 error]
   [3] ./src/Toggle.jsx 243 bytes {0} [built] [failed] [1 error]
   [4] ./src/Nav.jsx 241 bytes {0} [built] [failed] [1 error]
   [5] ./src/NavItem.jsx 245 bytes {0} [built] [failed] [1 error]
   [6] ./src/NavIcon.js 250 bytes {0} [built] [failed] [1 error]
   [7] ./src/NavText.js 250 bytes {0} [built] [failed] [1 error]

ERROR in ./src/Nav.jsx
Module parse failed: Unexpected token (12:21)
You may need an appropriate loader to handle this file type.
| 
| class Nav extends PureComponent {
|     static propTypes = {
|         componentType: PropTypes.any,
| 
 @ ./src/index.js 4:0-39

ERROR in ./src/NavItem.jsx
Module parse failed: Unexpected token (15:21)
You may need an appropriate loader to handle this file type.
| 
| class NavItem extends PureComponent {
|     static propTypes = {
|         componentType: PropTypes.any,
| 
 @ ./src/index.js 5:0-47

ERROR in ./src/SideNav.jsx
Module parse failed: Unexpected token (16:21)
You may need an appropriate loader to handle this file type.
| 
| class SideNav extends PureComponent {
|     static propTypes = {
|         componentType: PropTypes.any,
| 
 @ ./src/index.js 1:0-32

ERROR in ./src/Toggle.jsx
Module parse failed: Unexpected token (7:21)
You may need an appropriate loader to handle this file type.
| 
| class Toggle extends PureComponent {
|     static propTypes = {
|         componentType: PropTypes.any,
| 
 @ ./src/index.js 3:0-45

ERROR in ./src/NavIcon.js
Module parse failed: Unexpected token (7:4)
You may need an appropriate loader to handle this file type.
| // For component matching
| NavIcon.defaultProps = {
|     ...NavIcon.defaultProps,
|     componentType: NavIcon
| };
 @ ./src/index.js 6:0-47

ERROR in ./src/NavText.js
Module parse failed: Unexpected token (7:4)
You may need an appropriate loader to handle this file type.
| // For component matching
| NavText.defaultProps = {
|     ...NavText.defaultProps,
|     componentType: NavText
| };
 @ ./src/index.js 7:0-47

webpack.config. js

var pkg = require('./package.json');
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var findImports = require('find-imports');
var stylusLoader = require('stylus-loader');
var nib = require('nib');
var publicname = pkg.name.replace(/^@\w+\//, ''); // Strip out "@trendmicro/" from package name
var banner = [
    publicname + ' v' + pkg.version,
    '(c) ' + new Date().getFullYear() + ' Trend Micro Inc.',
    pkg.license,
    pkg.homepage
].join(' | ');
var localClassPrefix = publicname.replace(/^react-/, ''); // Strip out "react-" from publicname

module.exports = {
    devtool: 'source-map',
    entry: path.resolve(__dirname, 'src/index.js'),
    output: {
        path: path.join(__dirname, 'lib'),
        filename: 'index.js',
        libraryTarget: 'commonjs2'
    },
    externals: []
        .concat(findImports(['src/**/*.{js,jsx}'], { flatten: true }))
        .concat(Object.keys(pkg.peerDependencies))
        .concat(Object.keys(pkg.dependencies)),
    module: {
        rules: [
            // http://survivejs.com/webpack_react/linting_in_webpack/
            {
                test: /\.jsx?$/,
                loader: 'eslint-loader',
                enforce: 'pre',
                exclude: /node_modules/
            },
            {
                test: /\.styl$/,
                loader: 'stylint-loader',
                enforce: 'pre'
            },
            {
                test: /\.jsx?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
            },
            {
                test: /\.styl$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: 'css-loader?camelCase&modules&importLoaders=1&localIdentName=' + localClassPrefix + '---[local]---[hash:base64:5]!stylus-loader'
                })
            },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader'
            },
            {
                test: /\.(png|jpg|svg)$/,
                loader: 'url-loader'
            }
        ]
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                // This has effect on the react lib size
                NODE_ENV: JSON.stringify('production')
            }
        }),
        new webpack.NoEmitOnErrorsPlugin(),
        new stylusLoader.OptionsPlugin({
            default: {
                // nib - CSS3 extensions for Stylus
                use: [nib()],
                // no need to have a '@import "nib"' in the stylesheet
                import: ['~nib/lib/nib/index.styl']
            }
        }),
        new ExtractTextPlugin('../dist/' + publicname + '.css'),
        new webpack.BannerPlugin(banner)
    ],
    resolve: {
        extensions: ['.js', '.json', '.jsx']
    }
};

.babelr c

{
    "presets": ["env", "stage-0", "react"],
    "plugins": [
        "transform-decorators-legacy"
    ]
}

Буду очень признателен, если кто-нибудь сможет мне помочь по этому вопросу.

...