Closed nicolasdezena closed 5 years ago
Hello,
Since v4, ObjectModel is distributed as ES Module, and no longer CommonJS. See release notes here: https://github.com/sylvainpolletvillard/ObjectModel/releases/tag/v4.0.0
import { Model } from "objectmodel"
I also get a similar error in the legacy build for meteor, even though i am using the correct syntax. There i think it is due to meteor's transpiling but I don't know how to get around it (so i am stuck on 3.7.7).
yeah, unfortunately the transition from CommonJS to ES modules is not super smooth, mainly because of Node.js modules plan and bundler/transpiler issues.
I like the idea of distributing ESM, because it lets the final user use its own build tools, decide which environments to target with @babel/preset-env, and gets great tree-shaking and code elimination thanks to static analysis of ES modules. It's more initial work for the library consumer, but at the end he gets a custom build that is optimized for his specific needs. ESM also improves the developer experience with better autocompletion, for example, compared to a UMD bundle.
In the future, we can expect all the browsers/environments/tools to fully adopt ES modules by default and just work. Nethertheless, I hesitated when publishing v4 if this move was too early or not. Do you think I should still provide a UMD bundle for v4 ? Or let you do it by yourself ?
Trying to set this up with Node10 and babel proved to be an exercise in frustration.
So yes a commonjs variant would be appreciated.
In the meantime, I found a way to fix this without having to provide a UMD bundle myself. The pika.dev service is providing UMD versions of my library for free. You can take it from their CDN here: https://umd.cdn.pika.dev/objectmodel/v4
Docs have been updated, and you can find a usage example here too: https://github.com/sylvainpolletvillard/ObjectModel/blob/master/test/umd.html
Even with webpack, I get this error.
please check my answers above
Hi guys,
I have an error when i put
const { Model } = require("objectmodel")
Error: