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
Issue when importing Mappersmith from a TypeScript file and using esbuild #414
Comments
Supported/documented use cases can be found in https://github.com/klippx/mappersmith-consumer/ and so far esbuild is not part of those. But it can be added, and should be added, especially if you can help me out. I am familiar with the thread you posted. EvanW explained it well, and for me I have had to push through this issue before, but my setup is different. I use tsc + node, and I got around the issue by using this node loader https://github.com/barhun/extensionless#readme - but IDK if it works for your use case since esbuild writes the dist folder whereas I am used to I have not personally used esbuild, but it seems like an good candidate to add to the mappersmith consumer project. I bootstrapped something here that replicates your issue, and if you want to you can review / comment what is wrong. It doesn't seem to work with the plugin either as there is a number of issues in the dist folder produced:
But lets not go into the details of that, we can keep that discussion in the PR if you want to join the effort. For this matter I would summarize is as follows:
|
This is it, our built artect does not have the extension provided, and thus we need to use
Even if we did "fix" it we would be fighting typescript and might find ourselves in trouble with type imports etc. It might be that we wont find a good solution to the root cause and actually have relative imports that includes |
Agree, the import should be fixed on the TS side, and actually producing workarounds does not feel like a sustainable solution in a long run. |
Hmm, in fact even without esbuild (trying to just run a js file) I've got this
package.json {
"volta": {
"node": "16.20.1" // v19 gives me same results
},
"name": "mappersmith-test",
"dependencies": {
"mappersmith": "^2.43.1"
},
"type": "module"
} test.js import forge from 'mappersmith'
console.log(forge) What am I doing wrong here? |
I think that your expectations are not wrong and that this should work. The esm output does not have the .mjs extensions like it should. We are using tsup to generate esm, but it only works if you use extensionless or another workaround to convince node to run it. I found related issues in tsup repo
I think I need to look into some hack to patch the Ideally the built dist/esm folder should "just work" for your simple use case here without any third party magic to accommodate for the sloppy esm code that tsup has produced. If you are interested in lending a hand or investigating you can take a look at |
I think I have fixed this now @manisenkov thanks a ton for valuable input and making this library better! Fixed in 2.43.2 |
Btw, I am not sure how things are working with node 16, we only have CI support for node 18 and node 20. It might be still some bad luck for you in node 16 land and I would recommend not using deprecated node versions. |
Thank you so much for fixing that, @klippx! |
Hi!
I'm trying to bump one of our projects from Mappersmith v2.42 to v2.43.1 and encounter an issue with new ESM modules. We're using Node v16 and esbuild v0.19.11 to bundle the project into one file. But build failed with an error
To repeat the issue
src/index.ts
esbuild.js
package.json
And then run
node esbuild.js
It seems to be that the issue happens because no
.mjs
extension are added in imports. I can temporarily patch it writing minimal plugin for esbuild, as described in this comment but perhaps there's a better way to fix it.The text was updated successfully, but these errors were encountered: