微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Webpack 热重载失败,并显示“意外的令牌 '['预期在类主体的开头打开 '{'”

如何解决Webpack 热重载失败,并显示“意外的令牌 '['预期在类主体的开头打开 '{'”

我将此 Boilerplate 与 React、Webpack、Babel 和热重载一起使用。 一切正常,直到我尝试添加 Chakra-UI

现在,加载失败,因为热重载无法导入 Chakra-UI 的导入之一。 SyntaxError: Unexpected token '['. Expected opening '{' at the start of a class body. 是我得到的错误

Browser Console Error

我相信这是导致错误文件

import { createMotionComponent } from '../../motion/index.js';
import { Drag } from '../../motion/features/drag.js';
import { Gestures } from '../../motion/features/gestures.js';
import { Exit } from '../../motion/features/exit.js';
import { Animation } from '../../motion/features/animation.js';
import { AnimateLayout } from '../../motion/features/layout/Animate.js';
import { MeasureLayout } from '../../motion/features/layout/Measure.js';
import { createDomMotionConfig } from './utils/create-config.js';
import { createMotionProxy } from './motion-proxy.js';

var allMotionFeatures = [
    MeasureLayout,Animation,Drag,Gestures,Exit,AnimateLayout,];
/**
 * HTML & SVG components,optimised for use with gestures and animation. These can be used as
 * drop-in replacements for any HTML & SVG component,all CSS & SVG properties are supported.
 *
 * @public
 */
var motion = /*@__PURE__*/ createMotionProxy(allMotionFeatures);
/**
 * Create a DOM `motion` component with the provided string. This is primarily intended
 * as a full alternative to `motion` for consumers who have to support environments that don't
 * support `Proxy`.
 *
 * ```javascript
 * import { createDomMotionComponent } from "framer-motion"
 *
 * const motion = {
 *   div: createDomMotionComponent('div')
 * }
 * ```
 *
 * @public
 */
function createDomMotionComponent(key) {
    return createMotionComponent(createDomMotionConfig(allMotionFeatures,key,false));
}

export { createDomMotionComponent,motion };

但是,当我从 Webpack 配置中删除“HotModuleReplacementPlugin”以禁用热重载时,一切正常。是不是我遗漏了什么(也许是一个 babel 插件做了一些奇怪的事情?)或者我在 react-hot-loader 中遇到了一个错误

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。