timarney / react-app-rewired

Override create-react-app webpack configs without ejecting
MIT License
9.81k stars 425 forks source link

Your project's `baseUrl` can only be set to `src` or `node_modules`. Create React App does not support other values at this time. #464

Closed kcubero27 closed 4 years ago

kcubero27 commented 4 years ago

I opened this issue here but I'm not 100% sure if it's this library causing it. It only happens when I upgrade react-app-rewired.

The current versions I have are:

"react-app-rewired": "2.1.6",
"react": "16.13.1"

When I try to generate a build, I get the following output:

Error: Your project's `baseUrl` can only be set to `src` or `node_modules`. Create React App does not support other values at this time.
    at getAdditionalModulePaths (get-ui/node_modules/react-scripts/config/modules.js:59:9)
    at getModules (get-ui/node_modules/react-scripts/config/modules.js:139:33)
    at Object.<anonymous> (get-ui/node_modules/react-scripts/config/modules.js:149:18)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (get-ui/node_modules/react-scripts/config/webpack.config.js:30:17)

However, if I use react-app-rewired v2.1.5 it works fine.

I actually have a baseUrl inside the tsconfig.json file:

{
...
"baseUrl": "src",
...
}

I would really appreciate if you could help me to solve this issue. Thank you! 👍

dawnmist commented 4 years ago

This is built into react-scripts. It comes from here.

However, src is supposed to be one of the permitted values. Can you test changing it to:

{
  "baseUrl": "./src",
}

and see if that works?

If not, I suspect that there may be an issue in determining the app path properly. To work out what the paths are that react-scripts is working with when it checks if baseUrl is valid, make the following change to config-overrides.js (simply for logging):

module.exports = {
  webpack: (config, env) => {
    // ...this is the normal function that is exported from config-overrides.
    return config;
  },
  paths: (paths, env) => {
    console.log(JSON.stringify(paths));
    return paths;
  }
}

Let me know how you go. If the adjustment to the baseUrl definition did not fix it, please post the console.log for the paths (only need the project root path and below - please obscure everything before the project root directory).

kcubero27 commented 4 years ago

@dawnmist Seems that adding the following in the tsconfig.json works! 🎉

{
  "baseUrl": "./src",
}

Thank you very much for your help!