-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
TS and JS build files of npm package out of sync #231
Comments
* package.json improvements for es6 module default * specify files in package.json * remove esbuild-runner in favor of tsx
Can you try 2.0.0-alpha.6? I made some fixes to package.json, it might have been picking up an older CJS file by default https://unpkg.com/browse/[email protected]/dist/index.js linę 1941 should be fixed |
Thanks so much for the quick response. But somehow this gives me different issues. If I just swap [email protected] with [email protected] I get the following error: $ bun run src/index.ts
1 | (function (entry, fetcher)
^
SyntaxError: Missing 'default' export in module '{...}/node_modules/protomaps-themes-base/dist/index.js'. My project runs in bun, but I also tested it with an empty Node project. I suppose that it must be something about the changes in the exports part of the package.json. If I modify Using 17 | "light": layers("protomaps","light"),
^
TypeError: layers is not a function. (In 'layers("protomaps", "light")', 'layers' is an instance of Object) Now I'm not an esbuild expert but I assume that with the new configuration my project picks up the compiled index.js file that is intended to run in the browser and there doesn't seem to be a way to tell it to do something else instead? Thanks again! |
I've got the same issue in Bun. Using alpha.6 I can fix it with the following exports property
These would be my suggestion to the |
@Edefritz are you using pmtiles npm package in your project? the current |
also am I correct in interpreting that this issue right now affects Bun and Bun only? |
Yes, I am using the npm package. But I tried editing some files manually to figure out what's going wrong. And no, I don't think it only affects bun. As I mentioned, I made a test with an empty node project as well and received the same error. Perhaps the issue with the current export is that the .js build is created with the I think @eknowles' suggestion to use conditional exports makes sense. |
Just to confirm -> getting the same issue when trying to import in Nuxt app. (yarn)
|
Can you try v2.0.0 that I just pushed? This fixes I don't have enough information to reproduce the exact environments mentioned above so if you still have issue please push a minimal repo with Bun or Nuxt to test. |
Great, that fixes it for me. Thanks so much! :) |
why the change of heart here @bdon? Up until 2.0.0alpha5 my project build correctly. Now I have to move an entire monorepo to ESM to build this project. :| |
@iwpnd the feedback I got in other issues (protomaps/PMTiles#287) as well as docs like https://nodejs.org/api/packages.html#dual-package-hazard was that we should prefer moving to ESM-only; for this case in particular is there a workaround, like using the generated style JSON instead of depending on the NPM package? |
That's a pretty extrem view. One that is not shared with a lot of other libraries of higher popularity in the ecosystem. I don't think you have educational duty to enforce, nor do I believe you want to. 😄
I believe you went the same route with the pmtiles package, so at the latest it'll bite me there. |
Fair! I wasn't aware of CJS projects using PMTiles, but I think CJS is important for migrating legacy projects to PMTiles if they're depending on a deprecated 3rd party API, etc. Is your CJS project a command-line NodeJS one? Trying to understand the background here. Since this project and the other JS ones (pmtiles, protomaps-leaflet) are all bought into ESBuild, we could add CJS support back in via a |
It's an express backend that uses pmtiles and this package to provide a basemap with different styling options. Since it has a bunch of dependencies with other parts of the monorepo, i'd have to move the entire thing. Again, that's not your problem, so I understand if you'd not like to provide CJS support. But I'd appreciate it nonetheless. :)
This sounds perfectly fine. 👍 |
Proposed change and relevant TypeScript issue that arises: #248 (comment) I don't know how much of a dealbreaker this is. |
Can't tell you without testing it, i think. |
* emit the CommonJS build as index.cjs. styles 3.0.1
My bad, wasn’t aware that you already released |
Hey @bdon In short, it doesn't work for me. Importing either
Or
respectively, because the default is ESM. I can use e.g. import { labels, noLabels } from 'protomaps-themes-base/require'; on import, but it would complain about missing type definitions, something I believe you pointed out in #248. |
I would like to create a complete, runnable example that demonstrates the issue, if not a runnable project at least:
At least |
so I created this:https://github.com/iwpnd/pmtiles-example-ts using a tsconfig like the above the projects builds no problem. The problem arises is when I change to:
I was able to build like so prior to v3, now this doesn't build anymore. Now I have to admit that I'm lacking some background on how all of this ties together I'm afraid. From my point of view something changed with v3 that would not allow my build to succeed. |
So your project uses |
What if you use: const themesBase = require('protomaps-themes-base');
console.log(themesBase.labels, themesBase.noLabels); |
that is correct. also, while it may build, it doesn't run because of
aside from mixing require and es import syntax is urgh, it works, yet there's no types. I don't yet quite understand why you drop the behaviour prior to pmtiles v3/protomaps-base-themes v2alpha5, when now we try to revert and support commonjs. |
This is because I have not added the conditional export for
Because pre 3.0.0 it was default CommonJS (no |
gotcha, makes sense. 👍
This is not supposed to be a problem. The other way around is however. 🤔
somewhat understandable, definitely debatable - but in the end the maintainers decision. Anyhow, I'd be happy to test anything you want me to test further. But also feel free dropping it entirely. Appears to be a me problem that I'll have to address on my end when the time comes. |
@iwpnd you can use I don't understand why your project used |
It is actually the preferred way to write typescript imports and works just fine for as long as the underlying third party package is not an esm module. Only the resulting javascript will contain require calls, which is why it doesn't work for esm modules. Thank you for spending time on this nonetheless. Much appreciated. 🙏 |
Yes, thanks for the link. So it looks like at build time we need to create a separate set of |
It looks like Turf depends on adopting https://github.com/egoist/tsup along with its configuration https://github.com/Turfjs/turf/blob/09e9ebdfeef561ddfc67070064f6b8b72eedebd9/tsup.config.ts to generate dual packages are there examples of other projects using |
A good writeup in the |
vercel/ai |
migrating protomaps/protomaps-leaflet#163 to tsup first before I do |
@iwpnd can you try |
Nice @bdon! The project builds! 🥳 |
3.1.0 is published |
Hi,
I discovered something unusual. When installing the latest [email protected], I expected that the improvement I suggested a while ago would be reflected.
According to the base_layers.ts it is. But checking the style after I updated the package in my code base, the output seemed exactly the same as before.
After a lot of back and forth debugging, I found that the compiled .js, .mjs and .cjs files in the node_modules folder, didn't seem to have been updated.
To rule out issues on my local installation, I checked the source of the package inside NPM: https://www.npmjs.com/package/protomaps-themes-base?activeTab=code
As you can see in the screenshots the contents of the JS and TS files don't match (zoom should be 6 in line 1927).
I'm not sure this is how it works but perhaps you didn't compile the files before publishing the package? Or I'm awfully lost 😄
The text was updated successfully, but these errors were encountered: