wallabyjs / quokka

Repository for Quokka.js questions and issues
https://quokkajs.com
1.18k stars 31 forks source link

X is not a constructor when using ts-node + Typescript project #214

Closed ktiedt closed 6 years ago

ktiedt commented 6 years ago

Issue description or question

Writing a really simple test using Dojo2 (typescript based) and quokka I run into UrlSearchParams_1.UrlSearchParams is not a constructor from the below code. (test file is a sibling of the UrlSearchParams.ts file in this case) and just to prove there is a constructor... you can see the declaration here: https://github.com/dojo/core/blob/master/src/UrlSearchParams.ts#L44

Sample code

import { UrlSearchParams } from './UrlSearchParams';

const searchParams = new UrlSearchParams('a=b&b=c&c=a');

const result = searchParams.keys();

Quokka.js Console Output

UrlSearchParams_1.UrlSearchParams is not a constructor
at Object.<anonymous> src/test.ts:3:0
at Module._compile module.js:652

Code editor version

Atom v1.27.1

OS name and version

OSX High Sierra (latest public version)

ArtemGovorov commented 6 years ago

Quokka is correctly reporting the runtime error. There is no named UrlSearchParams export, the module has a default export, so the import should be not:

import { UrlSearchParams } from './UrlSearchParams';

but:

import UrlSearchParams from './UrlSearchParams';
ktiedt commented 6 years ago

Well consider me embarrassed, I assumed since it was a named class it was also a named export, it is directly copied sample code from their codebase so that didn't help since I trusted they would have got their samples right :/

As for it working, the error certainly goes away, however, I still cannot get live output from quokka... even if I through in a console.log(result).

ktiedt commented 6 years ago
screen shot 2018-06-01 at 10 36 26 pm

For reference. (and no, there is nothing below that)

ArtemGovorov commented 6 years ago

Hmm, I have no issues running the exact same sample, in the same editor and the same node version:

screen shot 2018-06-02 at 3 28 15 pm

Have you opened the project in Atom? Looks like the version of TypeScript used in your case is the one that ships with Quokka (as opposed to the project's TypeScript version, like on my screenshot). It may mean that you haven't opened the project.

ktiedt commented 6 years ago

Have you opened the project in Atom? Looks like the version of TypeScript used in your case is the one that ships with Quokka (as opposed to the project's TypeScript version, like on my screenshot). It may mean that you haven't opened the project.

Good call, this made for a great end to a very long day of driving :) -- I had opened the project at core/src using atom . -- closing it and repeating from core/ does in fact make things work. Will have to keep that in mind since I seldom open things from the root when I can just CLI the file (and access the project).

I'm guessing there isnt a way to avoid that breaking things?

And thank you by the way, I know I've opened several bugs recently, really looking forward to learning more about y'alls amazing tool, just so far, finding all the ways to break I suppose :/

ArtemGovorov commented 6 years ago

I'm guessing there isnt a way to avoid that breaking things?

If it was a file that doesn't import anything, then it would work fine - Quokka can run it. However, when any other files are imported, ts-node comes into play and when it can't find a valid tsconfig.json (because the working directory is core/src and not core), then ts-node fails.

ktiedt commented 6 years ago

Gotcha, will keep that in mind, definitely enjoying the flexibility that Quokka has provided in live debugging :) Thanks again!