Coder Social home page Coder Social logo

[typing import error][help wanted] The {{ package-name }} library may need to update its package.json or typings. about microbundle HOT 8 CLOSED

FranciscoKloganB avatar FranciscoKloganB commented on June 11, 2024
[typing import error][help wanted] The {{ package-name }} library may need to update its package.json or typings.

from microbundle.

Comments (8)

rschristian avatar rschristian commented on June 11, 2024 1

Fair enough, up to you then. npx can consume from a somewhat ill-defined cache, so the consequence of not installing it into the project as you would any other tool is that it can use a really old version (if its around) or pull a newer version than the user expects (with breaking changes they might not be aware of). I've personally always been happy with adding even an occasionally-used tool to my package.json and prefer it to the nebulous npx behavior, but that's just me.

from microbundle.

rschristian avatar rschristian commented on June 11, 2024

Please provide a reproduction.

Some TS module resolutions require you add "types" your package.json#exports, i.e.,

{
  "main": "./dist/index.js",
  "exports": {
    "types": "./dist/index.d.ts",
    "require": "./dist/index.js",
    "default": "./dist/index.modern.mjs"
  },
  "module": "./dist/index.module.js",
  "unpkg": "./dist/index.umd.js",
  "source": "./index.ts",
  "types": "./dist/index.d.ts",
}

Edit:

How do I avoid creating a browser build.

You're not. This comes from Rollup, and can be safely ignored, though I have no clue how you're triggering it.

from microbundle.

FranciscoKloganB avatar FranciscoKloganB commented on June 11, 2024

I will add the explicit "exports.types" as you suggested. If that fails, I will try to create a reproduction.

In the meantime... I noticed that the "test-project" that I use to test my exports had a different tsconfig.json.

The "test-project" uses "moduleResolution": "Node", whereas my "real-project", uses "moduleResolution": "Bundler".

I can't recall why I opted to use Bundler over ESNext... 🤔

The "real-project" kind of runs bun build ./functions/some-serverless-fn --outdir ./dist from where my Appwrite Backend as a Service reads the JS file from. Maybe that's why I did it.

See bun recommendations [here](https://bun.sh/docs/typescript#suggested-compileroptions.

from microbundle.

rschristian avatar rschristian commented on June 11, 2024

"moduleResolution": "bundler" requires exports.types, yes, see: https://www.typescriptlang.org/tsconfig#moduleResolution

from microbundle.

FranciscoKloganB avatar FranciscoKloganB commented on June 11, 2024

Bless. Exports types worked. What a god send. Thanks for the prompt response @rschristian!

Question not at all related with microbundle, maybe you know how to do it.

It's my first time needing to add codegen utilities to a open-sourced package. Right now I am doing a recursive copy of codegen JS files and telling my users to run them like node node_modules/a_huge_path/file.js, do you happen to know how I could tell them to instead just do:

npx my-package script? Would it suffice to add the script to the package.json, like a regular project?

from microbundle.

rschristian avatar rschristian commented on June 11, 2024

Yay!

As for the second part, package.json#bin is what you're after. For example:

{
    "bin": "./dist/index.js"
}

Packages installed with this entry will be added to node_modules/.bin/ (typically through symlinks) which will allow you to run npx <package>, executing <package>/dist/index.js. If you wanted to offer it through a different name (like if it's namespaced, might be nicer to offer a shorter name), you can do so by making package.json#bin an object:

{
    "bin": {
        "short-name": "./dist/index.js"
    }
}

This'll allow npx short-name.

Full docs

Would it suffice to add the script to the package.json, like a regular project?

Depends a bit on what you want to offer I suppose. Do you want them to install & keep a copy in their project, or just offer a script to do something? npx is pretty loose here in that it'll run the package if it's already installed in the project, else, it'll pull it straight from NPM to run it. You don't necessarily need to tell users to install it/add it to a package.json if it's going to be more of a one-off or occasional thing.

from microbundle.

FranciscoKloganB avatar FranciscoKloganB commented on June 11, 2024

Hmm nice. I am creating a migration-tool for structured database migration management with Appwrite. To ensure "stuff" works as intended and avoid errors from manual procedures, I want the users to be able to generate "empty" migration files, with commands.

So the idea would be something like npx admt new <outdir> <description>; So I guess it's an occasional thing.

from microbundle.

FranciscoKloganB avatar FranciscoKloganB commented on June 11, 2024

Thanks so much for the tips! :)

from microbundle.

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.