React Rails Uncaught SyntaxError: Unexpected token '!'

React Rails Uncaught SyntaxError: Unexpected token '!'

我想知道如何解决以下错误:

Uncaught SyntaxError: Unexpected token '!'

对应的行是:

return new !(function webpackMissingModule() { var e = new Error("Cannot find module 'leaflet'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()).Attribution(props);

这是我的反应组件代码: app/javascripts/components/squad_map.jsx

import React from "react";
import { Map, Marker, Popup, TileLayer } from "react-leaflet";
import PropTypes from "prop-types";

class SquadMap extends React.Component {
    constructor() {
        super();
        this.state = {};
    }

    render() {
        return (
            <React.Fragment>
                <p>SquadMap</p>
            </React.Fragment>
        );
    }
}

export default SquadMap;

app/javascripts/packs/application.js

import "core-js/stable";
import "regenerator-runtime/runtime";
require("@rails/ujs").start();
require("turbolinks").start();
require("@rails/activestorage").start();
require("channels");

var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);
require("trix");
require("@rails/actiontext");

提前致谢

已通过以下方式升级到最新版本解决了这个问题: $ npm 已过时 -> $ npm 更新 [PACKAGE_NAME] 并配置 babel 代码转译。