How to configure react-script so that it doesn't override tsconfig.json on 'start'
I'm currently using create-react-app
to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to the default tsconfig.json generated by create-react-app:
"baseUrl": "./src",
"paths": {
"interfaces/*": [
"common/interfaces/*",
],
"components/*": [
"common/components/*",
],
},
However, every time I run yarn start
which basically runs react-scripts start
, it deletes my changes and generates the default configurations again.
How can I tell create-react-app to use my custom configs?
reactjs typescript create-react-app react-scripts
add a comment |
I'm currently using create-react-app
to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to the default tsconfig.json generated by create-react-app:
"baseUrl": "./src",
"paths": {
"interfaces/*": [
"common/interfaces/*",
],
"components/*": [
"common/components/*",
],
},
However, every time I run yarn start
which basically runs react-scripts start
, it deletes my changes and generates the default configurations again.
How can I tell create-react-app to use my custom configs?
reactjs typescript create-react-app react-scripts
From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.
– Boy With Silver Wings
Dec 15 '18 at 16:36
1
Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.
– Glenn
Jan 2 at 21:38
add a comment |
I'm currently using create-react-app
to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to the default tsconfig.json generated by create-react-app:
"baseUrl": "./src",
"paths": {
"interfaces/*": [
"common/interfaces/*",
],
"components/*": [
"common/components/*",
],
},
However, every time I run yarn start
which basically runs react-scripts start
, it deletes my changes and generates the default configurations again.
How can I tell create-react-app to use my custom configs?
reactjs typescript create-react-app react-scripts
I'm currently using create-react-app
to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to the default tsconfig.json generated by create-react-app:
"baseUrl": "./src",
"paths": {
"interfaces/*": [
"common/interfaces/*",
],
"components/*": [
"common/components/*",
],
},
However, every time I run yarn start
which basically runs react-scripts start
, it deletes my changes and generates the default configurations again.
How can I tell create-react-app to use my custom configs?
reactjs typescript create-react-app react-scripts
reactjs typescript create-react-app react-scripts
asked Dec 15 '18 at 16:03
CodeInternCodeIntern
13017
13017
From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.
– Boy With Silver Wings
Dec 15 '18 at 16:36
1
Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.
– Glenn
Jan 2 at 21:38
add a comment |
From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.
– Boy With Silver Wings
Dec 15 '18 at 16:36
1
Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.
– Glenn
Jan 2 at 21:38
From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.
– Boy With Silver Wings
Dec 15 '18 at 16:36
From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.
– Boy With Silver Wings
Dec 15 '18 at 16:36
1
1
Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.
– Glenn
Jan 2 at 21:38
Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.
– Glenn
Jan 2 at 21:38
add a comment |
3 Answers
3
active
oldest
votes
I was able to do this by using advice from this issue.
Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.
paths.json:
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"interfaces/*": [ "common/interfaces/*"],
"components/*": [ "common/components/*"],
}
}
}
tsconfig.json
{
"extends": "./paths.json"
...rest of tsconfig.json
}
add a comment |
Create React App does not currently support baseUrl
. However there is a workaround...to setup baseUrl
for both webpack and the IDE you have to do the following:
- Create a
.env
file with the following code:
NODE_PATH=./
- Create a
tsconfig.paths.json
file with the following code inside:
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"src/*": ["*"]
}
}
}
- Add the following line to
tsconfig.json
{
"extends": "./tsconfig.paths.json",
...
}
add a comment |
You can't and I am unsure when you will be able to. I have been trying to use baseUrl and paths so I can avoid relative imports but as you can see they are intentionally removing certain values. The "(yet)" is encouraging but (sigh) who knows when they will officially be supporting it. I recommend subscribing to this github issue to be alerted if/when this changes.
The following changes are being made to your tsconfig.json file:
- compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))
- compilerOptions.paths must not be set (aliased imports are not supported)
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53794875%2fhow-to-configure-react-script-so-that-it-doesnt-override-tsconfig-json-on-star%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I was able to do this by using advice from this issue.
Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.
paths.json:
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"interfaces/*": [ "common/interfaces/*"],
"components/*": [ "common/components/*"],
}
}
}
tsconfig.json
{
"extends": "./paths.json"
...rest of tsconfig.json
}
add a comment |
I was able to do this by using advice from this issue.
Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.
paths.json:
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"interfaces/*": [ "common/interfaces/*"],
"components/*": [ "common/components/*"],
}
}
}
tsconfig.json
{
"extends": "./paths.json"
...rest of tsconfig.json
}
add a comment |
I was able to do this by using advice from this issue.
Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.
paths.json:
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"interfaces/*": [ "common/interfaces/*"],
"components/*": [ "common/components/*"],
}
}
}
tsconfig.json
{
"extends": "./paths.json"
...rest of tsconfig.json
}
I was able to do this by using advice from this issue.
Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.
paths.json:
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"interfaces/*": [ "common/interfaces/*"],
"components/*": [ "common/components/*"],
}
}
}
tsconfig.json
{
"extends": "./paths.json"
...rest of tsconfig.json
}
answered Jan 2 at 22:02
GlennGlenn
754819
754819
add a comment |
add a comment |
Create React App does not currently support baseUrl
. However there is a workaround...to setup baseUrl
for both webpack and the IDE you have to do the following:
- Create a
.env
file with the following code:
NODE_PATH=./
- Create a
tsconfig.paths.json
file with the following code inside:
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"src/*": ["*"]
}
}
}
- Add the following line to
tsconfig.json
{
"extends": "./tsconfig.paths.json",
...
}
add a comment |
Create React App does not currently support baseUrl
. However there is a workaround...to setup baseUrl
for both webpack and the IDE you have to do the following:
- Create a
.env
file with the following code:
NODE_PATH=./
- Create a
tsconfig.paths.json
file with the following code inside:
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"src/*": ["*"]
}
}
}
- Add the following line to
tsconfig.json
{
"extends": "./tsconfig.paths.json",
...
}
add a comment |
Create React App does not currently support baseUrl
. However there is a workaround...to setup baseUrl
for both webpack and the IDE you have to do the following:
- Create a
.env
file with the following code:
NODE_PATH=./
- Create a
tsconfig.paths.json
file with the following code inside:
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"src/*": ["*"]
}
}
}
- Add the following line to
tsconfig.json
{
"extends": "./tsconfig.paths.json",
...
}
Create React App does not currently support baseUrl
. However there is a workaround...to setup baseUrl
for both webpack and the IDE you have to do the following:
- Create a
.env
file with the following code:
NODE_PATH=./
- Create a
tsconfig.paths.json
file with the following code inside:
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"src/*": ["*"]
}
}
}
- Add the following line to
tsconfig.json
{
"extends": "./tsconfig.paths.json",
...
}
answered Feb 11 at 15:02
MicrocipcipMicrocipcip
107216
107216
add a comment |
add a comment |
You can't and I am unsure when you will be able to. I have been trying to use baseUrl and paths so I can avoid relative imports but as you can see they are intentionally removing certain values. The "(yet)" is encouraging but (sigh) who knows when they will officially be supporting it. I recommend subscribing to this github issue to be alerted if/when this changes.
The following changes are being made to your tsconfig.json file:
- compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))
- compilerOptions.paths must not be set (aliased imports are not supported)
add a comment |
You can't and I am unsure when you will be able to. I have been trying to use baseUrl and paths so I can avoid relative imports but as you can see they are intentionally removing certain values. The "(yet)" is encouraging but (sigh) who knows when they will officially be supporting it. I recommend subscribing to this github issue to be alerted if/when this changes.
The following changes are being made to your tsconfig.json file:
- compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))
- compilerOptions.paths must not be set (aliased imports are not supported)
add a comment |
You can't and I am unsure when you will be able to. I have been trying to use baseUrl and paths so I can avoid relative imports but as you can see they are intentionally removing certain values. The "(yet)" is encouraging but (sigh) who knows when they will officially be supporting it. I recommend subscribing to this github issue to be alerted if/when this changes.
The following changes are being made to your tsconfig.json file:
- compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))
- compilerOptions.paths must not be set (aliased imports are not supported)
You can't and I am unsure when you will be able to. I have been trying to use baseUrl and paths so I can avoid relative imports but as you can see they are intentionally removing certain values. The "(yet)" is encouraging but (sigh) who knows when they will officially be supporting it. I recommend subscribing to this github issue to be alerted if/when this changes.
The following changes are being made to your tsconfig.json file:
- compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))
- compilerOptions.paths must not be set (aliased imports are not supported)
answered Jan 20 at 16:49
GentryRiggenGentryRiggen
35448
35448
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53794875%2fhow-to-configure-react-script-so-that-it-doesnt-override-tsconfig-json-on-star%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.
– Boy With Silver Wings
Dec 15 '18 at 16:36
1
Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.
– Glenn
Jan 2 at 21:38