Giter Site home page Giter Site logo

Comments (5)

danburzo avatar danburzo commented on June 3, 2024 2

Hi @VojtechVidra! What seems to be going on is some unintended tree-shaking of the ESM entry point src/index.js when you import something that the bundler deems to be free of side-effects.

Importing just converter seems to skip all the side-effects further down in the file:

import { converter } from "culori";

If instead you import the LCh converter directly, which is defined as a side-effect in the entry point, all the other side effects are executed and the code works:

import { lch } from 'culori';

If I understand correctly, Next.js 13 uses Turbopack, so that may be the place to open up an issue. I misread that, Next.js 13 uses a built-in Compiler, so the Next.js repo may be the place to log the issue. It feels to me like overeager tree-shaking. Admittedly, the way Culori is organized is a bit quirky!

This is not a problem for the CommonJS bundle because tree-shaking is not applicable there.

from culori.

danburzo avatar danburzo commented on June 3, 2024 1

In [email protected] I've replaced sideEffects: false with an array of files producing side effects. This should allow both the tree-shaken version (using culori/fn) and the non-tree-shaken version to work correctly with more bundlers.

Tested the files in test/tree-shaking/ with esbuild, rollup, and parcel. Let me know how this new setup works for you!

from culori.

marcelpi avatar marcelpi commented on June 3, 2024 1

I just updated to 3.1.2 and can confirm the build is working as expected in a Svelte app.
Thanks @danburzo , you rock dude.

from culori.

danburzo avatar danburzo commented on June 3, 2024

The issue may be caused by our usage of sideEffects: false; in package.json, which if I remember correctly was necessary in order to allow for tree-shaking ESM modules. I'm going to leave the issue open as we may want to revisit this value in the future, to offer better support for the various bundlers.

from culori.

marcelpi avatar marcelpi commented on June 3, 2024

The issue may be caused by our usage of sideEffects: false; in package.json, which if I remember correctly was necessary in order to allow for tree-shaking ESM modules. I'm going to leave the issue open as we may want to revisit this value in the future, to offer better support for the various bundlers.

I confirm this.

Same thing happens when creating a build with Svelte.
Local dev environment works as expected, whereas when creating a build I get some sort of error which traces back to the interpolate function.

I manually removed "sideEffects": false, from the package.json of culori and the build works fine afterwards.

from culori.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.