在Heroku上使用绝对路径时,Create-react-app构建失败

4
在我的CRA中使用绝对路径时,在heroku上构建步骤失败。
我的.env.local文件中有以下内容:
``` NODE_PATH=src/ ```
我还在我的heroku设置中使用了这个环境变量。我尝试在heroku上使用“heroku-postbuild”脚本构建我的应用程序(它只运行“react-scripts build”)。我使用一个express服务器来提供这个构建文件夹并代理请求到各种API。
这是我得到的错误:
``` remote: Running heroku-postbuild (yarn) remote: yarn run v1.14.0 remote: $ react-scripts build remote: Creating an optimized production build... remote: Failed to compile. remote: remote: ./src/app/App.js remote: Cannot find module: 'checklist/Checklist'. Make sure this package is installed. remote: remote: You can install this package by running: yarn add checklist/Checklist. remote: remote: error Command failed with exit code 1. ```
Checklist.js文件位于“src/checklist/Checklist.js”。
有什么办法可以让这个工作?

你有没有解决这个问题?还是同样的问题? - hecontreraso
2个回答

0

我曾经遇到过这个问题,似乎是由于我的本地文件与提交到git的文件大小写不同造成的。例如,如果你有一个文件Checklist.js提交到了git,并且正在尝试import checklist from 'checlist/checklist.js',请运行git mv [...]/checklist.js [...]/Checklist.js

请参见此问题评论以获取帮助我解决问题的原始答案。


-2
只需在项目根目录下创建一个jsconfig.json文件,并粘贴以下内容(如果您使用src作为绝对导入的起点)。
{
  "compilerOptions": {
    "baseUrl": "./src"
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接