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

Fix baseUrl for NODE_PATH=src #5692

Closed
Timer opened this issue Nov 2, 2018 · 11 comments
Closed

Fix baseUrl for NODE_PATH=src #5692

Timer opened this issue Nov 2, 2018 · 11 comments

Comments

@Timer
Copy link
Contributor

Timer commented Nov 2, 2018

title

@niekert
Copy link

niekert commented Nov 3, 2018

Out of curiosity, would this allow absolute imports in TS apps created with create-react-app?

I've been trying to get it working and remember setting the NODE_PATH for JS projects. Loving the Typescript support 🙏

@Timer
Copy link
Contributor Author

Timer commented Nov 3, 2018

Yes, this will start permitting absolute imports in TS apps.

@tkazec
Copy link

tkazec commented Nov 5, 2018

Will this work with NODE_PATH=. as well?

I use this because it forces referencing src/, removing any ambiguity as to what is being imported.

@Timer
Copy link
Contributor Author

Timer commented Nov 5, 2018

Not sure if we'll allow . or not, there's always #5118 which will let you import via @/.

@dawnmist
Copy link

dawnmist commented Nov 6, 2018

We use the same as @tkazec, so that instead of having to have a dozen different absolute paths (plus paths for files that were under src itself...I'm not sure how src/App.ts would be referenced without the src prefix present) we only had one, and thus had a lot less risk of a name clash between one of our folders and an npm package name.

@unzico
Copy link

unzico commented Nov 18, 2018

@niekert
If you're looking for a way to enable absolute path imports, see #5118 (comment)

@jamesg1
Copy link

jamesg1 commented Feb 11, 2019

Adding "baseUrl": "./src", to my compilerOptions options in tsconfig.json worked for me.

@mindjuice
Copy link

@jamesg1 That's been working for me for over a year too, but on this new project, whenever I run yarn start, the baseUrl entry is removed from tsconfig.json!

Anyone have a way to prevent this?

@jamesg1
Copy link

jamesg1 commented Mar 5, 2019

@mindjuice Yeah I think there was a change which resets the baseUrl might have to use react rewired.

See #5118 (comment)

@agido-freudenreich
Copy link

@mindjuice The tsconfig is rewritten on every start. You have to use extends (#5645 (comment))

@iansu iansu modified the milestones: 2.1.6, 2.1.x, 3.x Mar 6, 2019
dsm23 added a commit to dsm23/david-murdoch-smarter-click that referenced this issue Apr 11, 2019
A list of users now appears on the home page, the "add user" from has been moved to different endpoint. This list is driven by a react context. Netlify settings have been added. A .env file that should allow for absolute paths in imports has been added. It is not working, I should suspect that my config is correct, this just may need sorting with react-scripts, facebook/create-react-app#5692.

sidebar css moved to assets folder. Constants folder added. Both fields in the form now use required validation and will alert the user what is invalid. formState is displayed below the form.
@iansu
Copy link
Contributor

iansu commented Apr 23, 2019

We now support setting baseUrl in tsconfig.json (and jsconfig.json). Currently you can only set it to node_modules (the default) and src. We are hoping to add support for aliases in the near future and may look at relaxing the restriction on baseUrl.

NODE_PATH is now deprecated and since you can just set baseUrl directly I think this can be closed.

@iansu iansu closed this as completed Apr 23, 2019
@lock lock bot locked and limited conversation to collaborators Apr 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants