Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsconfig.json was overwrote by react-scripts #1

Closed
altjz opened this issue Mar 28, 2020 · 6 comments
Closed

tsconfig.json was overwrote by react-scripts #1

altjz opened this issue Mar 28, 2020 · 6 comments

Comments

@altjz
Copy link

altjz commented Mar 28, 2020

I add the paths config in tsconfig.json, it looks like:

"paths": {
    "@library/*": ["library/*"]
}

But when I start up("start": "react-app-rewired start), it shows up this log, my tsconfig.json would be overwrote. (paths disappears)

The following changes are being made to your tsconfig.json file: 
  - compilerOptions.paths must not be set (aliased imports are not supported)

Solution
Refer this extends
Use tsconfig.paths.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@library/*": ["library/*"]
    }
  }
}

then add this line in tsconfig.json
"extends": "./tsconfig.paths.json"

my config-overrides.js

const { alias, configPaths } = require('react-app-rewire-alias')

module.exports = function override(config) {

  alias({
    ...configPaths('tsconfig.paths.json')
  })(config);
  return config
}

cheers 🍺

@EmiyaYang
Copy link

EmiyaYang commented Apr 12, 2020

It should be added to the README.

@oklas
Copy link
Owner

oklas commented Apr 13, 2020

Thanks for support friends. Your supports very significant for me. I have not so much time. I am creating an opensource for all and it is very significant for me to feel support and to know that you like and to know it is used and on demand. I created not so long ago my twitter and facebook accounts where I will post news about new features and future updates - subscribe for a news. 🍺

@ruffy0002
Copy link

Hi, tested this with

"react-scripts": "3.4.0",
"react-app-rewire-alias": "^0.1.6",
"react-app-rewired": "^2.1.6",

and this workaround does not seem to be working. The following message still appears (Checked that this error is not reported when I delete "paths" out of tsconfig.paths.json)

The following changes are being made to your tsconfig.json file:
  - compilerOptions.paths must not be set (aliased imports are not supported)

Can I check which version was this workaround tested with?

@sbue
Copy link

sbue commented Jun 23, 2020

^ I am seeing the above issue as well

@kenbonilla
Copy link

kenbonilla commented Jul 1, 2020

@ruffy0002
The above solution worked for me with the following dependencies:

"react-scripts": "3.4.1",
"react-app-rewire-alias": "^0.1.6",
"react-app-rewired": "^2.1.6",
"typescript": "^3.9.5",
Full list of dependencies
  "dependencies": {
    "@types/jest": "^24.9.1",
    "@types/jquery": "^3.3.38",
    "@types/node": "^12.12.47",
    "@types/react": "^16.9.35",
    "@types/react-dom": "^16.9.8",
    "@types/react-transition-group": "^4.4.0",
    "@types/url-parse": "^1.4.3",
    "@types/uuid": "^8.0.0",
    "axios": "^0.19.2",
    "classnames": "^2.2.6",
    "font-awesome": "^4.7.0",
    "idb": "^5.0.4",
    "jquery": "^3.5.1",
    "primeflex": "^1.2.0",
    "primeicons": "^4.0.0-rc.2",
    "primereact": "^4.2.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-error-boundary": "^2.2.2",
    "react-numpad": "^5.1.1",
    "react-scripts": "3.4.1",
    "react-transition-group": "^4.4.1",
    "typescript": "^3.9.5",
    "url-parse": "^1.4.7",
    "uuid": "^8.2.0"
  },
  "devDependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "cra-append-sw": "^2.7.0",
    "del": "^5.1.0",
    "gifsicle": "4.0.1",
    "gulp": "^4.0.2",
    "gulp-imagemin": "^7.1.0",
    "react-app-rewire-alias": "^0.1.6",
    "react-app-rewired": "^2.1.6",
  }

set up tsconfig.json, tsconfig.paths.json, and config-overrides.js exactly as described above and set up your package.json scripts as instructed in the ReadMe

Now, when you go to use the alias in your IDE it still doesn't work.

Either restart/reload your IDE or do a build - do this every time you add a new alias. For VS Code, you can reload the window by opening the command palette (ctrl+shift+p) reload window

Eventually you will build your project, and when you do you will get the following warning. Ignore this warning, it doesn't appear to have any impact on the build process.

The following changes are being made to your tsconfig.json file:
  - compilerOptions.paths must not be set (aliased imports are not supported)

This has been tested with these IDEs:
VS Code (May 2020 v 1.46.1)
Eclipse (2019-12 v 4.14.0) with Codemix (2020.4.7).


@oklas I truly appreciate your hard work on this tool, you've saved me from such a headache!

@oklas
Copy link
Owner

oklas commented Nov 21, 2020

I rewrite and simplify docs to show what need to do for these days to make it worked (instead of which files and options are exists and its possible values). I also added an example project it works - check it 🚴‍♂️ (currently it uses temporary patch - see #9). Feel free to ask. Subscribe to twitter for a news.👍

@oklas oklas closed this as completed Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants