javascript - create-react-app 中的 require('google-closure-library') 导致 Uncaught SyntaxError: Identifier 'module' has been declared
问题描述
这可以通过 3 个简单的步骤重现。
创建一个新的Create React App:
npx create-react-app myApp
安装Google Closure 库:
npm install google-closure-library
将闭包库导入 App.js:
require('google-closure-library');
现在运行 react 应用程序,npm start
我们在浏览器控制台中遇到异常。Uncaught SyntaxError: Identifier 'module' has already been declared
.
尝试使用goog.require(...)
或任何类似的结果会导致编译器错误说明:Failed to compile. 'goog' is not defined
. 这可能是第一个错误的副作用。
google 闭包库中似乎有一个变量与 react 应用程序中已经存在的module
另一个变量不能很好地配合使用。module
google-closure-library 只是与 create-react-app 不兼容还是这里发生了什么?
解决方案
推荐阅读
- html - 无法使用铬/铬拖动 URL
- linux - postgresql +如何打印所有主机
- python - Python - 使用 Pandas 遍历 excel 文件的行
- opencv - 使用摄影参考比例进行图像校正
- python - 尝试将对象列转换为 int 时出错
- javascript - 使用 Typescript 和类发送 mailgun 消息
- datetime - 如何在谷歌应用程序脚本中将时间戳“新日期()”格式化为新加坡时区?
- python - 尝试从列表中获取列表的长度以及基于每个列表的长度的计数
- git - 如何在 Visual Studio Code 中推送 Git 标记?
- javascript - 如何在 NOSQL 中建立关系,例如 firestore