-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
commonJS needs ./
in package.json exports field
#100
Comments
Yes. This is written in node js. ES6 is one way of writing nodejs. You can I wish I could offer more help, but your question is a bit thin on details. If you would like to create a public repo and ask specific questions related to that code, I would be happy to help. Best. |
Thanks for helping out! And yes, sorry, I confused Whenever I try to
I get this error:
I've tried with node 12 and 14. |
In addition, if I change the
|
Then, when attempting the recommended solutions here, I get a few different issues. Not sure where to go next. |
Can we reopen and rename the issue if this makes sense? @RIAEvangelist |
./
in package.json exports field
The error you have gives the clue that is needed import dominos from 'dominos' it is suggesting you do dominos=import('dominos'); However, I made a quick project to test this, and indeed I need to add './' to the exports field in Tests are running now and I will publish once uploaded and tagged |
Awesome! Thanks so much! Wondering if there could be an example using commonJS. Even with that tip, I'm still a little off. But looks like adding the
Error:
|
fixed in |
Thanks @PatrickAlphaC |
If you want to add a hint for ES6 example import {Order,Customer,Item,Payment,NearbyStores} from 'dominos'; for const {Order,Customer,Item,Payment,NearbyStores}=import('dominos'); |
hmm... seem I need to put more effort into this... I just ran a test const {Order,Customer,Item,Payment,NearbyStores}=import('dominos');
console.log({Order,Customer,Item,Payment,NearbyStores})
//returned
{
Order: undefined,
Customer: undefined,
Item: undefined,
Payment: undefined,
NearbyStores: undefined
} |
OK, I got a working example of using this in I'm going to add this to the docs. let dominos;
(async () => {
dominos=await import('dominos');
//need to await dominos promise completion
//because ES6 is async by nature
start();
})()
//start app from a function instead of
//in the global scope
function start(){
console.log(dominos.Order);
}
//outputs
[class Order extends DominosFormat] |
I am adding better docs for this now, but just to keep @PatrickAlphaC aware, here is the basis to let your code use the same code as the examples. (async () => {
const dominos=await import('dominos');
//importing variables into the global like this just allows us to use the same code
//from the ESM implementation for the commonJS implementation
//This is the same as an ESM import of
//import {Address,NearbyStores,Store,Menu,Customer,Item,Image,Order,Payment,Tracking,urls,IsDominos} from 'dominos'
Object.assign(global,dominos);
//need to await dominos promise completion
//because ES6 is async by nature
start();
})()
function start(){
//any example code would work as-is in here because the dominos guts are imported now.
const n='\n';
console.log(
n,
Address,n,
NearbyStores,n,
Store,n,
Menu,n,
Customer,n,
Item,n,
Image,n,
Order,n,
Payment,n,
Tracking,n,
urls,n,
IsDominos,n
);
} |
OK, I just pushed the changes to master. See the short example as above in the main README.md And the detailed example with a full order in the CommonJS.md |
THANK YOU!!! THIS WORKS!!!! |
Can we use this with like an express server? I’m having a hard time
The text was updated successfully, but these errors were encountered: