reactjs - npm 运行构建命令“未安装包”中的错误
问题描述
我创建了一个 react-redux 应用程序,它工作正常。现在我想用react-scripts package在 IIS 上发布它。当我使用npm run build时,我收到一条错误消息:
Creating an optimized production build...
Failed to compile.
.\src\_services\report.service.js
Cannot find module: 'config'. Make sure this package is installed.
You can install this package by running: npm install config.
但是这个配置是 webpack.config.js 中的一个外部,我写它有一个全局应用程序配置选项 这是我的 webpack.config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development',
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader'
}
]
},
plugins: [new HtmlWebpackPlugin({
template: './public/index.html',
favicon: "./src/favicon.ico"
})],
devServer: {
historyApiFallback: true
},
externals: {
// global app config object
config: JSON.stringify({
apiUrlAuthentication: 'https://localhost:5001',
apiUrlOperations: 'https://localhost:5003',
apiUrlReports: 'https://localhost:5005',
apiUrl: 'https://localhost:5001'
})
}
}
我以这种方式使用配置:
import config from "config";
import { authHeader } from "../_helpers";
export const reportService = {
getTransactionsReport
};
function getTransactionsReport(JSONfield) {
console.log("JSONFilterfield", JSONfield);
const requestOptions = {
method: "POST",
dataType: "json",
headers: authHeader(),
body: JSON.stringify(JSONfield),
};
console.log("requestBody", requestOptions);
return fetch(
`${config.apiUrlReports}/api/myApi`,
requestOptions
).then(handleResponse);
}
我的错误是什么,或者我能为这个构建做些什么?
解决方案
推荐阅读
- javascript - 具有两个功能的 Django 应用程序按钮
- c# - ASP.net MVC 客户端使用补丁 API 获取错误请求 400 返回
- r - 将几个笛卡尔坐标组合成 1 个平均输出
- git - 如何在 Git 中更改我的全局用户名?注意:我已经使用 config 指定了全局用户名和电子邮件
- java - BUILD FAILURE - 无法在项目上执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test)
- django - 由 django-compressor/libsass 生成的压缩 CSS 文件不会在服务器第一次启动时提供,但会在后续启动时提供
- python - OSError:[Errno 22] 打开文件时参数无效
- javascript - 在 React 中使用 axios 获取 api 的问题
- android - 在回收站视图中设置按钮时出错?
- bash - 如何将二进制浮点值写入 bash 中的文件?