The Boundary I Hit Running Node Scripts in a React Project
Hitting conflicts between ES modules, ts-node, and tsconfig taught me to treat browser code and file-generation scripts as separate runtime environments.
Joohwan Yu · Founder, Full Stack Developer
Toris · Published
Contents
I spent time on configuration problems while trying to run a TypeScript script inside a React project. An import that worked in the browser gave a different result in Node, and running with ts-node while keeping ES module syntax meant I also had to check the scope of tsconfig. A small file-generation task turned into an audit of the runtime environment.
The same language was not the same runtime
Browser code is resolved by a bundler. A Node script is resolved by Node and the tool that runs it. Import paths, file extensions, and module formats can look alike, but the conditions differ depending on which tool ends up reading them. The frontend config being right was no guarantee that the script’s run config was right.
At the time, I wanted to use ES module syntax instead of going back to require. What mattered here wasn’t adding options one by one to match a syntax preference, but checking that the project’s type, the compiler’s module settings, and the run command all pointed the same way.
Narrowing the scope of the config file
I also thought about restricting include to scripts and excluding unneeded src in the script config. Without this boundary, running a file-generation script drags in UI-side types and browser-only dependencies. Conversely, if you split everything even though you need shared types, you end up maintaining the same model twice.
Today I would share the data types and pure conversion functions that don’t depend on a runtime first. I’d keep file reading and writing on the Node side and leave DOM and browser storage access on the UI side. I wouldn’t put all the code under one config just because it lives in the same repository.
I should have left a reproducible command
What I regret is that while solving the environment problem, it was easy to lose track of which combination of settings was the final standard. If I did it again, I would briefly record the Node and package manager versions, the run command, and the input and output locations. I’d also check that running the same command in another terminal produces the same files.
When I deal with development environments now, I separate making an error go away from defining a run contract. A setup I could explain why it runs that way helped for much longer than a setup that happened to run once.
Technical reference: Node.js ECMAScript modules
Advertisement