javascript - 如何在 React JS 中设置环境变量..?

标签 javascript node.js reactjs maven

我是 React JS 的新手。我正在尝试从 React App 构建 war 文件但卡在下面的某个地方。它给了我以下错误。

Creating an optimized production build...

Treating warnings as errors because process.env.CI = true.
Most CI servers set it automatically.

Failed to compile.



./src/Home.js
  Line 2:   'AppNavbar' is defined but never used  no-unused-vars
  Line 3:  'Link' is defined but never used       no-unused-vars
  Line 4:  'Button' is defined but never used     no-unused-vars
  Line 4:  'Container' is defined but never used  no-unused-vars

./src/App.js
  Line 5:   'MenuBar' is defined but never used        no-unused-vars
  Line 6:   'PrivilegeList' is defined but never used  no-unused-vars
  Line 8:   'logo' is defined but never used           no-unused-vars


  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! my-app@0.1.0 build: `react-scripts build`
  npm ERR! Exit status 1
  npm ERR!
  npm ERR! Failed at the my-app@0.1.0 build script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

  npm ERR! A complete log of this run can be found in:
    npm ERR!     D:\ReactJS-workspace\my-app\npm\cache\_logs\2018-10-19T07_44_19_233Z-debug.log
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 01:36 min
    [INFO] Finished at: 2018-10-19T13:14:19+05:30
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (npm run build (compile)) on project my-app: Command execution failed.: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

下面是我的文件夹结构。

enter image description here

我想设置 process.env.CI = false 如何在 React JS 中设置环境变量?

最佳答案

要为当前流程执行设置它,只需编辑您的 package.json 文件并修改“构建”脚本,如下所示:

"scripts": {
"start": "react-scripts start",
"build": "set \"CI=false\" && react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject" }

这会将 CI 环境变量设置为“false”。现在您可以使用 CI 变量集执行构建命令:

npm run build

关于javascript - 如何在 React JS 中设置环境变量..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52888214/

相关文章:

javascript - 在 componentDidMount 中卸载什么

javascript - Ruby 哈希到 JavaScript

javascript - 基本 JavaScript if 与 else if

javascript - 为什么我们需要像json2这样的js库来处理json?

node.js - Strapi API : Set custom query service to find nearest location within a range?

node.js - Redis从set中获取key,然后在multi中获取他们的数据

javascript - 如何使用 .filter() 从数组中删除值?

javascript - 如何在点击时创建滑动DIV?

Node.js 路由发送到不正确的 Controller

javascript - React Hooks + Firebase Firestore onSnapshot - 正确使用带有反应钩子(Hook)的 firestore 监听器