-
Notifications
You must be signed in to change notification settings - Fork 45
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
bug: fixed bug when trying to import module using node esm and added … #190
Conversation
…documentation to use esm web bundles
"require": "./lib/cjs/index.js" | ||
}, | ||
"./esm": "bundles/esm.bundle.js", | ||
"./web": "bundles/web.bundle.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this not break the #152 (comment) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To reference the bundled web and esm you would use
import { WarpWebFactory } from 'warp-contracts/bundles/esm.bundle'
instead of
import { WarpWebFactory } from 'warp-contracts/esm'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I continue to struggle with this issue, but I have narrowed down the root cause. The ./lib/esm/index.js
build is not esm compliant, I don't know why it is not, but I do know when I switch the exports config to point the import
to cjs it works fine.
"exports": {
".": {
"import": "./lib/cjs/index.js",
"require": "./lib/cjs/index.js"
},
"./esm": "bundles/esm.bundle.js",
"./web": "bundles/web.bundle.js"
},
So that may be another option.
The current esm build results in this response:
file:///workspace/stamp-coin/copy-and-deploy.mjs:4
import { WarpFactory } from './warp/lib/esm/index.js'
^^^^^^^^^^^
SyntaxError: Named export 'WarpFactory' not found. The requested module './warp/lib/esm/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from './warp/lib/esm/index.js';
const { WarpFactory } = pkg;
For now, I am just pulling down the latest source and patching the package.json
npx degit warp-contracts/warp#v1.2.0-rc.1 warp
cd warp
npx json -I -f package.json -e 'this.exports.import = "./lib/cjs/index.js"'
yarn && yarn build:cjs
Please, let me know how I can help move this bug to fixed.
I believe that to make it compatible with .mjs files, we would need to add We will return to this next week. |
@twilson63 @ppedziwiatr I was able to make the .mjs file run correctly only using tsup npm package (https://github.com/egoist/tsup), looks cool and is based on esbuild but I'm not sure what's happening underneath. It requires a lot more tests but maybe it's a good start. |
Do we really need another weird library to run sth., that is considered as
a "standard"...?
Have you tried creating a very simple library and play with different
tsconfig settings?
Is `type: 'module'` the only way to make it work with mjs files?
niedz., 21 sie 2022, 15:56 użytkownik Asia ***@***.***>
napisał:
… @twilson63 <https://github.com/twilson63> @ppedziwiatr
<https://github.com/ppedziwiatr> I was able to make the .mjs file run
correctly only using tsup npm package (https://github.com/egoist/tsup),
looks cool and is based on esbuild but I'm not sure what's happening
underneath. It requires a lot more tests but maybe it's a good start.
—
Reply to this email directly, view it on GitHub
<#190 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUDH5TPRYMJVHSHU7DAE2SDV2IYRDANCNFSM53E3G74Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
microsoft/TypeScript#18442
This is insane...
niedz., 21 sie 2022, 16:32 użytkownik Piotr Pędziwiatr <
***@***.***> napisał:
… Do we really need another weird library to run sth., that is considered as
a "standard"...?
Have you tried creating a very simple library and play with different
tsconfig settings?
Is `type: 'module'` the only way to make it work with mjs files?
niedz., 21 sie 2022, 15:56 użytkownik Asia ***@***.***>
napisał:
> @twilson63 <https://github.com/twilson63> @ppedziwiatr
> <https://github.com/ppedziwiatr> I was able to make the .mjs file run
> correctly only using tsup npm package (https://github.com/egoist/tsup),
> looks cool and is based on esbuild but I'm not sure what's happening
> underneath. It requires a lot more tests but maybe it's a good start.
>
> —
> Reply to this email directly, view it on GitHub
> <#190 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AUDH5TPRYMJVHSHU7DAE2SDV2IYRDANCNFSM53E3G74Q>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
microsoft/TypeScript#18442 (comment)
niedz., 21 sie 2022, 16:37 użytkownik Piotr Pędziwiatr <
***@***.***> napisał:
… microsoft/TypeScript#18442
This is insane...
niedz., 21 sie 2022, 16:32 użytkownik Piotr Pędziwiatr <
***@***.***> napisał:
> Do we really need another weird library to run sth., that is considered
> as a "standard"...?
>
> Have you tried creating a very simple library and play with different
> tsconfig settings?
> Is `type: 'module'` the only way to make it work with mjs files?
>
> niedz., 21 sie 2022, 15:56 użytkownik Asia ***@***.***>
> napisał:
>
>> @twilson63 <https://github.com/twilson63> @ppedziwiatr
>> <https://github.com/ppedziwiatr> I was able to make the .mjs file run
>> correctly only using tsup npm package (https://github.com/egoist/tsup),
>> looks cool and is based on esbuild but I'm not sure what's happening
>> underneath. It requires a lot more tests but maybe it's a good start.
>>
>> —
>> Reply to this email directly, view it on GitHub
>> <#190 (comment)>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/AUDH5TPRYMJVHSHU7DAE2SDV2IYRDANCNFSM53E3G74Q>
>> .
>> You are receiving this because you were mentioned.Message ID:
>> ***@***.***>
>>
>
|
Another 'interesting' solution
microsoft/TypeScript#18442 (comment)
But this is all madness...I'm pretty sure that it will break sth in one of
those shitty web bundlers...
niedz., 21 sie 2022, 16:43 użytkownik Piotr Pędziwiatr <
***@***.***> napisał:
…
microsoft/TypeScript#18442 (comment)
niedz., 21 sie 2022, 16:37 użytkownik Piotr Pędziwiatr <
***@***.***> napisał:
> microsoft/TypeScript#18442
>
> This is insane...
>
>
> niedz., 21 sie 2022, 16:32 użytkownik Piotr Pędziwiatr <
> ***@***.***> napisał:
>
>> Do we really need another weird library to run sth., that is considered
>> as a "standard"...?
>>
>> Have you tried creating a very simple library and play with different
>> tsconfig settings?
>> Is `type: 'module'` the only way to make it work with mjs files?
>>
>> niedz., 21 sie 2022, 15:56 użytkownik Asia ***@***.***>
>> napisał:
>>
>>> @twilson63 <https://github.com/twilson63> @ppedziwiatr
>>> <https://github.com/ppedziwiatr> I was able to make the .mjs file run
>>> correctly only using tsup npm package (https://github.com/egoist/tsup),
>>> looks cool and is based on esbuild but I'm not sure what's happening
>>> underneath. It requires a lot more tests but maybe it's a good start.
>>>
>>> —
>>> Reply to this email directly, view it on GitHub
>>> <#190 (comment)>,
>>> or unsubscribe
>>> <https://github.com/notifications/unsubscribe-auth/AUDH5TPRYMJVHSHU7DAE2SDV2IYRDANCNFSM53E3G74Q>
>>> .
>>> You are receiving this because you were mentioned.Message ID:
>>> ***@***.***>
>>>
>>
|
But I would start with the above. It's basically what we're doing (two
separate builds into cjs and esm format) with additional step of adding
package.json files into esm and cjs dists.
niedz., 21 sie 2022, 16:50 użytkownik Piotr Pędziwiatr <
***@***.***> napisał:
… Another 'interesting' solution
microsoft/TypeScript#18442 (comment)
But this is all madness...I'm pretty sure that it will break sth in one of
those shitty web bundlers...
niedz., 21 sie 2022, 16:43 użytkownik Piotr Pędziwiatr <
***@***.***> napisał:
>
> microsoft/TypeScript#18442 (comment)
>
> niedz., 21 sie 2022, 16:37 użytkownik Piotr Pędziwiatr <
> ***@***.***> napisał:
>
>> microsoft/TypeScript#18442
>>
>> This is insane...
>>
>>
>> niedz., 21 sie 2022, 16:32 użytkownik Piotr Pędziwiatr <
>> ***@***.***> napisał:
>>
>>> Do we really need another weird library to run sth., that is considered
>>> as a "standard"...?
>>>
>>> Have you tried creating a very simple library and play with different
>>> tsconfig settings?
>>> Is `type: 'module'` the only way to make it work with mjs files?
>>>
>>> niedz., 21 sie 2022, 15:56 użytkownik Asia ***@***.***>
>>> napisał:
>>>
>>>> @twilson63 <https://github.com/twilson63> @ppedziwiatr
>>>> <https://github.com/ppedziwiatr> I was able to make the .mjs file run
>>>> correctly only using tsup npm package (https://github.com/egoist/tsup),
>>>> looks cool and is based on esbuild but I'm not sure what's happening
>>>> underneath. It requires a lot more tests but maybe it's a good start.
>>>>
>>>> —
>>>> Reply to this email directly, view it on GitHub
>>>> <#190 (comment)>,
>>>> or unsubscribe
>>>> <https://github.com/notifications/unsubscribe-auth/AUDH5TPRYMJVHSHU7DAE2SDV2IYRDANCNFSM53E3G74Q>
>>>> .
>>>> You are receiving this because you were mentioned.Message ID:
>>>> ***@***.***>
>>>>
>>>
|
Yeah, I was trying this one. I got 'Permission denied' when running sh script so I dropped the idea 🤡 but as I see simply running
should make it work. I'll try again and let you know. |
Weird af, .mjs works fine with
|
so I guess we'd need extensions for all the imported files? |
And how does it work in the example that I've sent? There is also some
additonal configuration in the main package.json file...
niedz., 21 sie 2022, 17:16 użytkownik Asia ***@***.***>
napisał:
… so I guess we'd need extensions for all the imported files?
—
Reply to this email directly, view it on GitHub
<#190 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUDH5TOLCGEYYS3YK7M7P53V2JB3TANCNFSM53E3G74Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I.e. this part
https://github.com/jwalton/solox/blob/4d86f8779329ffc47552a16d2bab60544ee78c65/package.json#L6-L15
niedz., 21 sie 2022, 18:50 użytkownik Piotr Pędziwiatr <
***@***.***> napisał:
… And how does it work in the example that I've sent? There is also some
additonal configuration in the main package.json file...
niedz., 21 sie 2022, 17:16 użytkownik Asia ***@***.***>
napisał:
> so I guess we'd need extensions for all the imported files?
>
> —
> Reply to this email directly, view it on GitHub
> <#190 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AUDH5TOLCGEYYS3YK7M7P53V2JB3TANCNFSM53E3G74Q>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
I dont think we should compare these libs... they have one-file package. The problem is not what is written in package.json (we have it compatible with them), I believe the problem is how we import classes etc. |
I'll play with it some more :)))) |
@asiaziola , we should probably store somewhere (probably here #209 ?) all the related articles, SO hints node and web bundlers docs/issues - that will document all the tricks that we're currently using to make all the versions work... |
I believe this has been finally fixed in |
…documentation to use ESM web bundles
Removed exports property from package.json, this property blocks the ability to consume the NodeJS ESM library using nodeJS ESM projects.
Also, I added some documentation on how to reference web-based ESM bundles.