Coder Social home page Coder Social logo

Comments (7)

RyanCavanaugh avatar RyanCavanaugh commented on April 30, 2024 2

We should at least update the error message to suggest the resolution mode assertion

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 30, 2024 1

@andrewbranch points out that the concerns in the linked issue are specific to resolution hitting different targets in upstream packages due to revisions in their package jsons, but this argument doesn't apply at all to local relative paths

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 30, 2024

Duplicate #52529 edit: maybe?

from typescript.

andrewbranch avatar andrewbranch commented on April 30, 2024

The currently intended behavior is that you’re supposed to silence this error by adding with { "resolution-mode": "import" } to assert that you’re doing what you’re doing on purpose. At minimum, we need to update this error message to suggest that workaround, but I was finding it hard to construct a message that adequately explains what’s wrong with this code, since I’m still somewhat skeptical that there’s anything wrong with this code.

from typescript.

jakebailey avatar jakebailey commented on April 30, 2024

I'm confused; isn't the context of this issue nodejs/node#51977, such that when that's "final", we need to have a new module resolution mode which re-allows require(ESM)? And that this issue isn't about anything else?

(Hm, maybe not, as the above was just a "side point" of sorts...)

from typescript.

Jason3S avatar Jason3S commented on April 30, 2024

@andrewbranch,

with { "resolution-mode": "import" }

This solves the my main issue. I did search for this, but wasn't able to figure it out based upon #53656. I was also trying to use verbatimModuleSyntax, but that doesn't work with CommonJS files.

I completely missed typescriptlang.org Stable Support resolution-mode in Import Types. I knew about with { type: "json" }.

By the way, the "value" of "resolution-mode" doesn't seem to matter for local files.

This works fine.
src/code.cts

import type { User } from './models.mts' with { "resolution-mode": "require" };

Which leads to the question of why resolution-mode is necessary for local files.

@jakebailey,

I'm confused; isn't the context of this issue nodejs/node#51977, such that when that's "final", we need to have a new module resolution mode which re-allows require(ESM)? And that this issue isn't about anything else?

(Hm, maybe not, as the above was just a "side point" of sorts...)

It is a "side point", I was using it as part of the argument that importing ESM files from a CJS file is necessary to support. Given that, it would also preclude the need for with { "resolution-mode": "import" }

from typescript.

andrewbranch avatar andrewbranch commented on April 30, 2024

Yeah, if that lands without a flag, there will be a new module mode / nodenext will be updated to support it without error. There’s nothing to do on that front yet.

from typescript.

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.