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

Support for native esm packages with typescript #672

Closed
bhvngt opened this issue Aug 21, 2021 · 2 comments
Closed

Support for native esm packages with typescript #672

bhvngt opened this issue Aug 21, 2021 · 2 comments
Assignees

Comments

@bhvngt
Copy link

bhvngt commented Aug 21, 2021

Issue description or question

Making quokka work with native esm project files and typescript

Sample code

tsconfig.tsnode.json

{
	"include": ["src/**/*", "tests/**/*"],
	"exclude": ["node_modules/*", "coverage/*"],
	"ts-node": {
		"transpileOnly": true,
	},
	"compilerOptions": {
		"target": "esnext",
		"module": "esnext",
		"lib": ["dom", "esnext"],
		"moduleResolution": "node",
		"strict": true,
		"forceConsistentCasingInFileNames": true,
		"importsNotUsedAsValues": "error",
		"incremental": true,
		"types": ["node", "jest"],
		"isolatedModules": false
	}
}

package.json

{
...
"type": "module"
...
}

b.ts

export const b: string = "Hello World!"

a.ts

({
	"nativeEsm": true
})

import {b} from "./b"

console.log(b);

Quokka.js Console Output

Cannot find module './src/b' imported from ./src/a.js
	at resolve /Volumes/DATA/XXXX/Library/Application%20Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/212.5080.39/IntelliJ%20IDEA%202021.2%20EAP.app.plugins/quokka-intellij/dist/runners/node/quokka@1.0.0/hooks.mjs:77

Code editor version

Webstorm v? 2021.2

OS name and version

OSX 11.5.2

@bhvngt bhvngt changed the title support of native esm packages with typescript Support for native esm packages with typescript Aug 21, 2021
@NikGovorov
Copy link
Member

Hi @bhvngt,

We've implemented the support of ESM for ts-node, please update Quokka plugin to v1.0.306.

({
  nativeEsm: true
});

import { b } from "./b.js";

console.log(b);

Note if you import a file without specifying an extension then you need to set --experimental-specifier-resolution to node:

({
  nativeEsm: true,
  env: {
    params: {
      runner: "--experimental-specifier-resolution=node",
    },
  },
});

import { b } from "./b";

console.log(b);

@bhvngt
Copy link
Author

bhvngt commented Aug 25, 2021

Thanks a ton for the quick turnaround. You guys truly rock.

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

3 participants