-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Create React App (CommonJS, ESNext) + Path Alias + Module (Import/Export) + NodeJS + TSConfig.json #10995
Labels
Comments
Could you please make a codesandbox or a ts playground? |
jdavis-software
changed the title
ReferenceError: Cannot access { variable } before initialization
Create React App (CommonJS, ESNext) + Path Alias + Module (Import/Export) + Node@14+
May 21, 2021
jdavis-software
changed the title
Create React App (CommonJS, ESNext) + Path Alias + Module (Import/Export) + Node@14+
Create React App (CommonJS, ESNext) + Path Alias + Module (Import/Export) + NodeJS
May 21, 2021
jdavis-software
changed the title
Create React App (CommonJS, ESNext) + Path Alias + Module (Import/Export) + NodeJS
Create React App (CommonJS, ESNext) + Path Alias + Module (Import/Export) + NodeJS + TSConfig.json
May 21, 2021
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
This was referenced Nov 24, 2023
This was referenced Jan 26, 2024
This was referenced Feb 11, 2024
This was referenced May 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Overview
Stop... Slow... Down... and Chill... 😅 if you're having a problem with your CRA module import/export syntax or path aliases, after upgrading either
react-scripts
,typescript
, ornodeJS
look no further, I've spent hours going through and consolidating and organizing the information to resolve your issue you're welcome 😄 to thank me later.Problem
It all simply boils down to this... CommonJS vs ES6 CRA wants ES6 and Typescript wants CommonJS
Requirements
This repo gives you a fresh install of the latest CRA - ReactScripts + TypeScript, make sure you update or download the latest version of NodeJS (currently 14.17.0)
Dependencies
<=4.0.3
<=4.2.4
<=14.17.0
Bug Description
After upgrading my packages to
[email protected]
and[email protected]
I'm receiving this error:This is related to exporting function expressions during declaration like this example:
Most of the application is written in this shorthand fat arrow function expression syntax, and this has always worked previously in the past before this update. After doing more research it looks like this problem is related to the module option inside compilerOptions declared in the
tsconfig.json
file.Problem Overview
The problem seems to be with the following esnext value inside the
module
option:Now changing this back to commonjs should resolve this problem, however after updating the option to the following:
Then running
npm run start
, you would think this would work, however, CRA/Webpack goes into thetsconfig.json
file and reverts it back to the previousesnext
module, thus again failing and causing the reference error:Does anyone have a solution, to allow export declarations of fat arrow function expressions, yet?
Useful Reference Links That May Help You!
extends
base overidesKeywords
Appreciate
If this helped you and save you time... feel free to send (BAT) - Basic Authentication Tokens... I need more coffee and dinners 😅
BAT Token Address - 0x1A62e25073a9038647c235509b4349988eED19Ae
Anyways wanted to spread peace, love and happiness to everyone. I love what I do and I hope everyone reading this is having a great day, take care guys!
The text was updated successfully, but these errors were encountered: