question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: `Cannot read property 'length' of undefined` with `tsx` file and `jsx: "preserve"` setting

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ezolenkocommented, May 26, 2022

@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)

1reaction
ghostcommented, Jul 9, 2017

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 with outFile - 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

"scripts": {
  "build": "tsc",
  "start": "http-server -a localhost",
  "dev": "run-p \"build -- -w\" start"
},
...
"dependencies": {},
"devDependencies": {
  "typescript": "2.4.1",
  "npm-run-all": "4.0.2",
  "http-server": "0.10.0"
}
...

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found