我懒于在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'));
这有什么问题,我该如何解决?
答案 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了解更多详细信息。