React-Scripts 3.0.0更新后延迟加载时出现“模块解析失败”错误

时间:2019-05-02 14:55:38

标签: reactjs react-scripts

我懒于在React应用程序中加载组件,并且一切正常。但是,在react-scripts 3.0.0更新之后,我不断收到“模块解析失败:意外令牌”错误,如下所示:

./src/routes/App.js 22:9
Module parse failed: Unexpected token (22:9)
You may need an appropriate loader to handle this file type.
| import { Loader } from '../components/Preloaders/Loader';
| var ClippedDrawer = lazy(function () {
>   return import('../components/Drawer');
| });
| var Settings = lazy(function () {

这是App.js文件的开头:

import React, { lazy, Suspense } from 'react';
import {
    Router,
    Route,
    Switch
} from 'react-router-dom';

import { Loader } from '../components/Preloaders/Loader';

const ClippedDrawer = lazy(() => import('../components/Drawer'));
const Settings = lazy(() => import('../containers/Settings/Settings'));
const NotFound = lazy(() => import('../containers/NotFound'));

这有什么问题,我该如何解决?

1 个答案:

答案 0 :(得分:0)

找到了解决方案:(但是,请为您的项目进行备份,以防失败)。

  • 删除node_modules
  • 删除package-lock.json package.json

在终端机中:

  • 运行npm install react-scripts@latest
  • 运行npm install

访问https://github.com/facebook/create-react-app/issues/6673了解更多详细信息。