我正在尝试使用 Vite 创建 React 应用程序的生产版本。当我运行 npm run dev 命令时,应用程序将启动并且似乎可以正常工作,但在构建过程中,我总是会因某些第三方依赖项而收到此类解析器错误,表明它包含意外的令牌。
我使用的是节点 19.1.0。
我的配置文件中是否缺少某些内容或者可能是什么?
[commonjs--resolver] Unexpected token (705:2) in C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/axios/lib/utils.js
file: C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/axios/lib/utils.js:705:2
703: toFiniteNumber,
704: findKey,
705: global: _global,
^
706: isContextDefined,
707: ALPHABET,
error during build:
SyntaxError: Unexpected token (705:2) in C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/axios/lib/utils.js
at pp$4.raise (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20972:13)
at pp$9.unexpected (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:18273:8)
at pp$5.parseIdent (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20903:10)
at pp$5.parsePropertyName (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20707:109)
at pp$5.parseProperty (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20634:8)
at pp$5.parseObj (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20597:21)
at pp$5.parseExprAtom (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20332:17)
at pp$5.parseExprSubscripts (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20148:19)
at pp$5.parseMaybeUnary (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20114:17)
at pp$5.parseExprOps (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20041:19)
Run Code Online (Sandbox Code Playgroud)
该项目是使用 React 和 TypeScript 初始化的。我必须为几个需要节点依赖项的库配置 polyfill。看起来vite.config.ts像这样:
import …Run Code Online (Sandbox Code Playgroud) 我无法解决这个问题,我该如何解决这个问题?
import React, { Component } from "react";
import "./Main.css";
import { FaSearch, FaEdit, FaWindowClose } from "react-icons/fa";
export default class Main extends Component {
state = {
pesquisaNFE: "",
resultado: [],
};
handleSubmit = (e) => {
e.preventDefault();
const { resultado } = this.state;
let { pesquisaNFE } = this.state;
pesquisaNFE = pesquisaNFE.trim();
if (resultado.indexOf(pesquisaNFE) !== -1) return;
const newSearch = [...resultado];
this.state({
resultado: [...newSearch, pesquisaNFE],
});
};
Run Code Online (Sandbox Code Playgroud)
错误:
