reactjs - 未捕获的 SyntaxError:意外的标记 '<' | 在“纱线添加 xlsx”之后 | 反应打字稿
问题描述
我正在用 React 开发项目(类型脚本)。我想为导出/导入 excel 文件添加新功能,我决定使用 xlsx 库https://www.npmjs.com/package/xlsx 所以我的问题是我运行了“yarn add xlsx”并且我的应用程序给了我错误“未捕获的语法错误:意外的令牌 '<' |”。我没有做任何导入,只是 yarn add xlsx 并且出现了这个错误。[![在此处输入图像描述][1]][1] 编译成功,没有其他错误。
奇怪的是,我发现我什么时候会在我的项目中做这个 hack:
npm install xlsx
yarn install
然后一切正常。我在不同的计算机上尝试了在同一个项目中添加 xlsx,但它在任何地方都不起作用......但后来我决定使用 npm 在本地添加的 xlsx 实现一些基本功能,并将我的项目部署在没有“npm install xlsx”的 linux docker 上,并且它在那里工作!
也许文件系统或 fs 库有问题?
编辑: 新信息 事实证明,我什么时候会做这样的场景
- 纱线安装
- 纱线添加 xlsx
一切正常
但如果我愿意
- 纱线安装
- 纱线添加 xlsx
- 纱线安装
出现错误!
所以在运行 yarn install 之后,安装了一些依赖项,这就是它失败的原因这不好,因为当我提交我的更改时,其他开发人员将使用“yarn install”安装依赖项
解决方案
I had unexpected token because I used %PUBLIC_PATH% variable in my index.html so I have to define this variable in .env file and of course I have it there
PUBLIC_PATH:/my-app/
But I didn't have this variable in .env.development file and everything was just fine until I updated react-scripts. So in react-scripts 3.2.0 it was by default "/" and after I updated react scripts to 3.4.0 it was failing with unexpected token error. I simply added
PUBLIC_PATH:/
to my .env.development file and everything works now
推荐阅读
- c# - 放置静态字符串的最佳位置在哪里
- docker - Weblogic 没有出现在 Dockerder 容器中
- c# - asp.net页面加载太多功能
- c# - 如何将表单数据“发布”到数据库中的 2 个表中
- python - 如何在 tkinter 中将 jpg 图像作为图标添加到根窗口
- django - 将带有大 IN 子句的 Django ORM 查询转换为表值构造函数
- javascript - 使用 JavaScript/CSS 在 HTML 元素的边框正下方添加属性值
- python - 在保留索引的同时删除包含 NaN 的行
- python - 如何禁用 geckodriver 在 Selenium(Python 3)上的登录?
- python - 无法使用 JSON 数据的 API 上传到 BigQuery