Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use JS/TS objects like Map and Date #755

Closed
Darksoulsong opened this issue Mar 8, 2022 · 3 comments
Closed

Can't use JS/TS objects like Map and Date #755

Darksoulsong opened this issue Mar 8, 2022 · 3 comments

Comments

@Darksoulsong
Copy link

Issue description or question

Is this issue related to Quokka not outputting the expected results of your code?: Yes

Sample code

const map = new Map();
// or
const date = new Date();

Quokka.js Console Output

​​​​​Quokka PRO 'Untitled-1.ts' (node: v16.13.2, TypeScript: v4.5.5, plugins: jsdom-quokka-plugin)​​​​
 
Error ./quokka.ts (1,17): Cannot find name 'Map'. Did you mean 'map'? 

Code editor version

Visual Studio Code v1.64.2

OS name and version

Ubuntu 20.04.3 LTS

@smcenlly
Copy link
Member

smcenlly commented Mar 8, 2022

We couldn't reproduce your problem using a fresh project with your same packages. I suspect it's related to your tsconfig.json.

Could you please check that this repo works for you?

  1. From the CLI: git clone https://github.com/wallabyjs/quokka-755
  2. Change to newly created quokka-755 folder
  3. Run npm install
  4. Open in VS Code and start Quokka on quokka.ts file.

If it works for you, can you please change tsconfig.json with the tsconfig from your project? I expect it will break. Please share that configuration for us and we can take a look at what's wrong with it for you.

I expect that due to your compiler settings, you will also get the same problem if you run npx ts-node quokka.ts from the command-line. If this is the case, your compiler settings will have to be fixed/overridden to make Quokka work.

@Darksoulsong
Copy link
Author

Darksoulsong commented Mar 9, 2022

Hello @smcenlly , thanks for the quick reply.

I cloned your repo and it works for me, I think you're right about my tsconfig settings.
I'm working on a microfrontend with single spa and my tsconfig extends some specific configuration in order to work (ts-config-single-spa).

This is what I have in my tsconfig.json file:

{
  "extends": "ts-config-single-spa",
  "compilerOptions": {
    "jsx": "react-jsx",
    "declarationDir": "dist"
  },
  "files": ["src/management-app-avd.tsx"],
  "include": ["src/**/*"],
  "exclude": ["src/**/*.test*", "node_modules"]
}

@smcenlly
Copy link
Member

smcenlly commented Mar 9, 2022

I took a look at the TypeScript compiler options for ts-config-single-spa (see below):

{
  "compilerOptions": {
    "esModuleInterop": true,
    "module": "esnext",
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "lib": [
      "dom",
      "es5",
      "scripthost",
      "es2015",
      "es2015.promise",
      "es2016.array.include",
      "es2018"
    ],
    "declaration": true,
    "emitDeclarationOnly": true
  }
}

The line:

    "emitDeclarationOnly": true

will cause the compiler to only generate .d.ts files (without any code). This was causing Quokka to fail. We've updated the latest version of Quokka to explicitly override this setting as it never makes sense to run Quokka with this compiler option set to true.

Please update your Quokka for VS Code extension to v1.0.450+. It will fix the problem for you.

@smcenlly smcenlly closed this as completed Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants