2

After switching to use absolute paths, although my local builds still work fine, Github CI build fails with this error:

./src/App.js
Cannot find module: 'components/Layout'. Make sure this package is installed.

How can I make Firebase/Github CI also search the src directory?

Arash
  • 522
  • 7
  • 24
  • could you share the build command that is executed in CI and locally? also, the assumption is that create-react-app is used, correct? – Sergey Semashko Dec 16 '20 at 04:00
  • Yes, create-react-app is used. Build command: npm install && CI=false npm run build. Same with local: npm run build – Arash Dec 16 '20 at 04:07
  • Have you created a `.env` file at the root with inside `NODE_PATH=src/` ? – Magofoco Dec 18 '20 at 23:14
  • I did try that although it's been deprecated in favor of jsconfig.json. Message in build: ```Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app. ``` – Arash Dec 18 '20 at 23:19

1 Answers1

0

Creating jsconfig.json with the following configuration should do the trick:

{
  "compilerOptions": {
    "baseUrl": "src"
  },
  "include": [
    "src"
  ]
}

I've tried creating a sample repo with the setup you mentioned and GitHub actions (I hope this is what you meant by GitHub CI) job did create build properly.

  • That is exactly what I have (same as the link in the question). I'm using firebase to set up the CI (Github action). This is what I followed: https://create-react-app.dev/docs/deployment/#firebase – Arash Dec 19 '20 at 05:05
  • I followed the instructions and was able to set this up, check out https://github.com/ten-sis/so-absolute-paths/pull/1. I'm going to remove the repo in a couple of weeks. I had to switch from yarn to npm because `npm ci` command required package-lock.json. If you still have the same error, maybe try double-checking your repo that all the configs are matching what's in my repo. – Sergey Semashko Dec 20 '20 at 04:17
  • could you change one of your css imports to absolute and try? – Arash Dec 20 '20 at 04:49
  • 1
    Figured out my mistake. I had some files that were lower case in remote but upper case in local. My filesystem is not case sensitive, so local builds didn't fail, but CI runs on ubuntu which is case sensitive. Awarding the bounty as a thank you for your help! – Arash Dec 21 '20 at 16:47