Coder Social home page Coder Social logo

Cannot import package about smol-toml HOT 5 CLOSED

Hocdoc avatar Hocdoc commented on May 27, 2024
Cannot import package

from smol-toml.

Comments (5)

cyyynthia avatar cyyynthia commented on May 27, 2024

Hi, that's indeed a problem!

What version of TypeScript are you using? Is the library actually impossible to import or is the problem only related to typing information?

from smol-toml.

cyyynthia avatar cyyynthia commented on May 27, 2024

Actually, I've just tried and I seem to be able to reproduce this using stock TS config. By specifying moduleResolution to node16 (or nodenext), TypeScript will actually resolve the types using my package.json's exports specification solving this issue.

This is not ideal, and considering I have a way to avoid this issue completely I'll change that in a future release. In the meantime, using the workaround described above should work.

from smol-toml.

Hocdoc avatar Hocdoc commented on May 27, 2024

Sorry for my late response and thanks for your moduleResolution-tip!

from smol-toml.

Wakeful-Cloud avatar Wakeful-Cloud commented on May 27, 2024

You need to add "types": "./dist/index.d.ts" and "main": "./dist/index.js" to the package.json (Reference).

from smol-toml.

cyyynthia avatar cyyynthia commented on May 27, 2024

TypeScript added support for NodeJS's exports field in TypeScript 4.7 and does correctly look up the types specified in this. main is unrelated to TypeScript and is useless in this context.

Realistically, failure to resolve the package's types is an indication of either an outdated TypeScript installation, or an improper configuration as I described above. While adding types at the root of the package is currently possible, it is only "accidental" and does not fully reflect the true Node Resolve Algorithm used.

References:

from smol-toml.

Related Issues (11)

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.