material-color-utilities icon indicating copy to clipboard operation
material-color-utilities copied to clipboard

Error importing module

Open IvanCardi opened this issue 2 years ago • 9 comments

Hi, I have the following error when trying to import any module from the library and then starting the server.

Issue material

I've tried installing the package via npm and yarn, but the issue still remains.

Any ideas?

IvanCardi avatar Mar 09 '23 09:03 IvanCardi

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

kwaa avatar Mar 09 '23 10:03 kwaa

Hi, unfortunately I already use ESM import syntax

import { Hct } from "@material/material-color-utilities";

Any other suggestion?

IvanCardi avatar Mar 09 '23 10:03 IvanCardi

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 avatar Mar 09 '23 10:03 kwaa

@kwaa Do you have any other ideas about how to resolve the issue?

IvanCardi avatar Mar 09 '23 11:03 IvanCardi

@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)

kwaa avatar Mar 09 '23 11:03 kwaa

It gives me the same error

IvanCardi avatar Mar 09 '23 11:03 IvanCardi

It gives me the same error

Maybe you could try creating a repo for me and others to look at?

kwaa avatar Mar 09 '23 12:03 kwaa

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.

WillsterJohnson avatar Mar 09 '23 17:03 WillsterJohnson