Giter Site home page Giter Site logo

ES Module support about tst-reflect HOT 15 CLOSED

hookyns avatar hookyns commented on June 1, 2024 1
ES Module support

from tst-reflect.

Comments (15)

Hookyns avatar Hookyns commented on June 1, 2024 1

You can create a PR with small change here:

function isESMModule(options: ts.CompilerOptions) {
// ref: https://www.typescriptlang.org/tsconfig#module
const target = options.target || ScriptTarget.ES3;
const module = options.module || (
[ScriptTarget.ES3, ScriptTarget.ES5].includes(target) ? ModuleKind.CommonJS : ModuleKind.ES2015
);
return [ModuleKind.ES2015, ModuleKind.ES2020, ModuleKind.ES2022, ModuleKind.ESNext].includes(module);
}

Add the new module kind to line 228.

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024 1

Published in [email protected].
TY for the PR.

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 1, 2024 1

Hmm, looks like it's still happening, https://stackblitz.com/edit/tst-reflect-issue-49-kdukpz

Get ctor is generated properly, but it adds this

const _ßr = require("tst-reflect");

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024 1

Should be fixed in [email protected] and [email protected].

Also there was some trouble with typelib mode in nodenext module, cuz of code related to ts-node. Hope it'll be okay.

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 1, 2024 1

With ts-node. Not aware of any issues, i know it won't accept .ts extension though. Even .ts files have to be imported with .js.

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 1, 2024

There's a require statement inserted in meta-writer/type-lib/TypeLibMetadataNodeGenerator.ts and
meta-writer/inline/InlineMetadataNodeGenerator.ts

factory.createIdentifier("require"),

I think that's why.

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024

There are some other places where are the requires generated, without using the isESMModule function.

But now I don't know if we modified the isESMModule correctly. It's not just the "module" option but combination with "moduleResolution" or package.json setting. I need to look into it a little bit.

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 1, 2024

yeah, you might be right. I was asking about top-level await in the typescript repo and they pointed me to this.

https://www.typescriptlang.org/tsconfig#moduleResolution

It has to be set to nodenext apparently.

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 1, 2024
import { ExpressionKind, } from 'tst-expression';
         ^^^^^^^^^^^^^^
SyntaxError: Named export 'ExpressionKind' not found. The requested module 'tst-expression' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'tst-expression';
const { ExpressionKind, } = pkg;

Can you add a esm export to the packages?

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 1, 2024

Oh look's like there is one issue. In es mode, imports have to use .js extension for relative imports. getCtor() will have to change. Currently, it's like import("./index")

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024

@avin-kavish Do you test it with ttsc or ts-node?

I found some note - from another contributor solving issues for ts-node - saying that ts-node has some issues with extensions .js/.ts so we removed the extensions cuz of it. But it was before nodenext option. They have to fixed it cuz of nodenext IMHO.

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024

Try [email protected], [email protected]

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 1, 2024

woot! works now.

from tst-reflect.

avin-kavish avatar avin-kavish commented on June 1, 2024

hmm... got another undefined getCtor() case

from tst-reflect.

Hookyns avatar Hookyns commented on June 1, 2024

I'm working on it. 👍

from tst-reflect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.