首页 > 解决方案 > create-react-app 中的 require('google-closure-library') 导致 Uncaught SyntaxError: Identifier 'module' has been declared

问题描述

这可以通过 3 个简单的步骤重现。

  1. 创建一个新的Create React Appnpx create-react-app myApp

  2. 安装Google Closure 库npm install google-closure-library

  3. 将闭包库导入 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 不兼容还是这里发生了什么?

标签: javascriptreactjscreate-react-appgoogle-closure-library

解决方案


推荐阅读