-
Notifications
You must be signed in to change notification settings - Fork 7
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
Error in ESM library #229
Comments
Hey @Dav2070, how are you? It's worth noticing that ES6 support is intended to third-party code (in your case, the modules related to you UI lib), not to the Pitsby's config file. The configuration file should be written using CommonJS syntax as follows: module.exports = {
// Your configuration. This file should be saved at the root of your project (aside package.json).
} Could you please paste your |
Hi @rafaelcamargo, thanks for the quick response! I am fine, I hope you are too :) I'm using the most basic config file here:
My index.js looks like this, simplified:
Is there a way to use it like this or do I have to compile my code to CommonJS? |
Hey, @Dav2070! Investigating the issue, I just learned that since your package.json defines type as module, Pitsby's configuration file must be named as In addition, I just released a couple other fixes for bugs I discovered along this investigation. So please install the latest version (1.32.2) and see if works fine for you now 😉 UPDATE Important to notice that your Pitsby's config file should be written as follows: // pitsby.config.cjs
module.exports = {
projects: [
{
engine: 'vanilla',
collectDocsFrom: './src'
}
],
scripts: [
{ src: './dist/index.js', type: 'module' }
// This is the way we tell Pitsby to add type as module to the script tag
// inserted into the index.html of the documentation
],
other: [
'./dist/src/'
]
// You need to declare all the files that "./dist/index.js" imports itself,
// otherwise they won't be found by the generated documentation.
} |
It now works flawlessly, thank you! |
Hey, @Dav2070! My fault 🤦♂️ . I made the necessary adjustments to support configuration files as Just released another version ( UPDATE
|
Thank you for the update! The doc files now work as well. I don't want to use even more of your time, but now I get the following error in the browser console: This is caused in the generated
If I use an url to import the package, it works. So this probably means the node_modules are not available in this context.
I'm not sure if this is a problem in my library and if I should compile my code in a different way. I will continue to search for a better solution and let you know if I find one. Thanks again for the help so far, I really appreciate that! |
Hey, @Dav2070! It seems to be something related to the import itself. In the Browser context, all import paths must be relative to the page on which it appears. In this case, I think it's necessary to:
More or less like this: // pitsby.config.cjs
module.exports = {
projects: [
{
engine: 'vanilla',
collectDocsFrom: './src'
}
],
scripts: [
{ src: './src/doc.importmap.js', type: 'importmap' },
{ src: './src/doc.index.js', type: 'module' }
],
other: [
'./dist/src/',
'./node_modules/lit/index.js'
]
} // src/doc.importmaps.js
{
'imports': {
'davComponents': '/external/dist/src/index.js',
'lit': '/external/node_modules/lit/index.js'
}
} // src/doc.index.js
import * as davComponents from 'davComponents';
window.davComponents = davComponents; If everything works, all your components will be available through the global variable For the next two weeks I'll be vacationing, but when I come back, I'll fork your repo and make some experiments. I never used Pitsby this way (importing ES6 files) and also never built components using Lit, so I am a bit curious to see if they work well with Pitsby ✌️ |
Hey @rafaelcamargo, thanks for the suggestion! I tried this some time ago, but Pitsby doesn't like the importmap file, as it contains only the json and no export or actual JS code. But I will need to try this again to tell you more. Anyway, I will wait for your results with my component lib. If there is something where I can help you, let me know! |
Hey, @Dav2070! Just found and resolved the remaining issues.
As you could see, I forked your repo and added to it the necessary commits to make Pitsby documentation work with your components. I also configured the deploy of the documentation using Firebase ($0 costs) to offer you an example on how to do that. You can visit it at https://dav-ui-components.web.app/ At last, all this challenges gave me an ideia. I will try (in the coming months) to create a dedicated Pitsby project only to explore Web Components and link this project on the current Pitsby's website to serve as an example on how to configure Pitsby to document Web Components using native ES6 modules ✨ If you need something else, please let me know. Have a nice time documenting your components 🙌 |
Thank you, this is perfect! I just implemented your changes and deployed to DigitalOcean, the docs are now available at components.dav-apps.tech 🎉 |
I want to use Pitsby in my JS library, but
pitsby build
always throws the following error:Digging deeper, as the file obviously exists, it turns out that Pitsby can't load it, as my library is an ES module, with package.json containing
"type": "module"
. This error is thrown here:Looking at #223, support for ES modules seems to be already implemented. But I don't understand how to use Pitsby in an ES module correctly. So any help with getting Pitsby to run would be much appreciated. You can find my library here, feel free to try it out if needed.
The text was updated successfully, but these errors were encountered: