Import ts files in static.config.js in React Static typescript template
See original GitHub issueReporting a bug?
After creating new React Static app with typescript template i can’t import .ts files in static.config.js. The similar situation happens when i change my static.config.js to static.config.ts and i try import .ts file then i got an errror:
=> File changed: /artifacts/react-static-browser-plugins.js
=> Updating build...
Failed to build! Fix any errors and try again!
multi /MY_PROJECT/node_modules/react-dev-utils/webpackHotDevClient.js (webpack)/hot/only-dev-server.js ../lib/bootstrapPlugins.js ../lib/bootstrapTemplates.js /MY_PROJECT/src/index.js
Module not found: Can't resolve '/MY_PROJECT/src/index.js' in '/MY_PROJECT/node_modules/react-static/node_modules'
Environment
Latest version of react-static create with typescript template
Steps to Reproduce the problem
Base your steps off of any freshly installed react-static template!
- react-static create
- select typescript template
- Open static.config.js
- Try to import in static.config.js any .ts file
- npm start / yarn start -> error
1a. Rename static.config.js to static.config.ts 2.Try to import .ts file -> error 3b. npm start / yarn start -> error
Expected Behavior
I should be able to import .ts files in static.config.js or build app with static.config.ts
Reproducible Demo
react-static create
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Import ts files in static.config.js in React Static typescript template
After creating new React Static app with typescript template i can't import .ts files in static.config.js. The similar situation happens ...
Read more >How to import .ts files in static.config.js in React Static ...
I have problem with import .ts files in static.config.js file in my project with React Static I got this error.
Read more >Import ts files in static.config.js in React Static typescript template -
After creating new React Static app with typescript template i can't import .ts files in static.config.js. The similar situation happens when i change...
Read more >How to use TypeScript with React: A tutorial with examples
Using TypeScript with React can increase development speed, improve code readability, and much more. Learn how to get yourself going.
Read more >Documentation - Modules - TypeScript
Any declaration (such as a variable, function, class, type alias, or interface) can be exported by adding the export keyword. StringValidator.ts. ts. export ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Not yet. I’ll make sure it’s somewhere once I finished the
export
command, so that I know who to allocate building the rest / what it would take. It’s mostly an internal rewrite, without too many “external”/public API changes.This is what my static looks like in RS 8:
It also allows you to use
.jsx
and.tsx
, because some plugins will allow you to pass inReact.ComponentType
.We also encourage people to use the TypeScript variant, or at least turn on
// @ts-check
, because the types correctly accepts for example the followingdata
values for routes:I believe this is not a plugin responsibility. It’s a matter of running react-static in a ts environment as you mentioned. It’s about how to write your SSG code, leveraging existing libraries, data sources, etc…
So, the good news is: I just tried to launch react-static with ts-node and everything seems to be working fine.
Then, from within
static-config.js
I am able to import typescript modules straight up.For now, I’m just running the
basic
example converted to typescript. I will continue down this path and see if/where it breaks 😉