material-color-utilities
material-color-utilities copied to clipboard
Error importing module
Hi, I have the following error when trying to import any module from the library and then starting the server.

I've tried installing the package via npm and yarn, but the issue still remains.
Any ideas?
It looks like you are using CJS require, and this is an ESM only package.
const { Hct } = require('@material/material-color-utilities') // ERR_PACKAGE_PATH_NOT_EXPORTED
import { Hct } from '@material/material-color-utilities' // success
If you really need CJS support instead of switching to ESM, you can use my fork: @importantimport/material-color-utilities
Hi, unfortunately I already use ESM import syntax
import { Hct } from "@material/material-color-utilities";
Any other suggestion?
That may have something to do with your environment. you can try it at Stackblitz and it imports and works fine:
https://stackblitz.com/edit/node-gje8kb
npm install & node index.mjs
@kwaa Do you have any other ideas about how to resolve the issue?
@kwaa Do you have any other ideas about how to resolve the issue?
Use my fork as above, or wait for this repo to support cjs... (probably not)
It gives me the same error
It gives me the same error
Maybe you could try creating a repo for me and others to look at?
Could you paste your own package.json file?
To use ESM features in Node, you need to have "type": "module" in your package.json file.
Given that you're using the correct ESM import but the error message shows that Node is using it's CJS loader (very top of your image; "node:internal/modules/cjs/loader:488"), it could be that you're missing that field.