首页 > 解决方案 > 模块解析失败意外令牌webpack反应nextjs

问题描述

尝试将react-native-elementsnpm 包导入 nextjs 应用程序,但 webpack 不喜欢该包中的文件之一。我是否在 next.config.js 文件中遗漏了一些配置或其他内容?

错误

error - ./node_modules/react-native-vector-icons/lib/create-multi-style-icon-set.js 108:23
Module parse failed: Unexpected token (108:23)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|   function createStyledIconClass(selectClass = '') {
|     class IconClass extends PureComponent {
>       static propTypes = styleNames.reduce((acc, name) => {
|         acc[name] = PropTypes.bool;
|         return acc;
Could not find files for /mypage in .next/build-manifest.json
Could not find files for /mypage in .next/build-manifest.json

next.config.js

const nodeExternals = require('webpack-node-externals');

module.exports = {
    webpackDevMiddleware: (config) => {
        config.watchOptions = {
            poll: 1000,
            aggregateTimeout: 300,
        };
        return config;
    },
    target: 'server',
    externals: [nodeExternals()],
    module: {
        rules: [
            {
                test: /\.m?js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env'],
                    },
                },
            },
        ],
    }
}

标签: javascriptwebpackbabeljsnext.js

解决方案


推荐阅读