Error: `Cannot read property 'length' of undefined` with `tsx` file and `jsx: "preserve"` setting
See original GitHub issueWhen processing a tsx
source file I get an error, however if I manually compile with tsc
I don’t get an error.
Environment:
Windows: 10 NodeJS: 7.10 NPM: 5.0.4
Project structure
./
tsconfig.json
package.json
rollup.config.js
src/
main.ts
jsx-utils.ts
components/
topbar.tsx
Here’s a gist with the relevant files in the above structure.
Error:
$ npm run build
> testtsx@1.0.0 build C:\repos\testtsx
> rollup -c
🚨 Cannot read property 'length' of undefined
src\components\topbar.tsx
I was using the older typescript plugin, rollup-plugin-typescript
and just require
’d in my local typescript, and that worked, but found that this existed so I gave it a whirl.
Let me know if I have something setup wrong! <3<3 Thanks for reading.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Cannot read property 'length' of undefined react - Stack Overflow
I would suggest to check first if the props is undefined or empty or even declared. for example:- const card = props &&...
Read more >Cannot Read Property Length of Undefined in JavaScript
The JavaScript TypeError: Cannot read property 'length' of undefined occurs when the length property is read on an undefined variable.
Read more >How to Read React Errors (fix 'Cannot read property of ...
This error usually means you're trying to use .map on an array, but that array isn't defined yet. That's often because the array...
Read more >[SOLVED] Cannot Read Property 'length' of Undefined in JS
This error occurs when you attempt to access the length property from a variable that has a value of undefined . const arr...
Read more >ERROR TypeError: Cannot read property title of undefined
HEY, SET YOUR LIKE THERE !!! ------------------- ----- LIKE --- https://codedocu.com/Software/Angular/Angular- Error /Solv...
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 FreeTop 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
Top GitHub Comments
@lastmjs this looks like a different error, could you open a new issue and fill in all the info? (and add more details on
experimentalPreserveModules
option)Thanks for pushing that out! I upgraded to this plugin over the older one, yay!
The Dream
For future reference; tsconfig now has an option
"jsxFactory": "h",
- it seems to eliminate the need for jsx/buble/babel plugin altogether. And since typescript also has a concatenation option withoutFile
- I’ll be experimenting with removing rollup as well. (I think I needed to ditch the jsx: preserve and use react target, but it’s not really react since I can specify the factory… But it does what I want!)I’m aiming for a zero dependency, minimal devDependency jsx workflow:
package.json
Living the dream! Perfect for quickly componentizing static sites. If needed, I can add a small data binding implementation, then I can have something pretty nifty.
I’m just experimenting in a quick personal project with a bare metal approach. No jquery, no framework, just lots of ~stolen~borrowed ideas xD.