Shopify CLI build error: ES modules import issue with directory resolution

Hey everyone, I’m stuck with a weird problem. My app was working fine last week, but now I’m getting an error when I try to build it. I haven’t changed anything, so I think it might be because of an update to the Shopify CLI.

When I run yarn run build, I get this error about directory imports not being supported for ES modules. It’s pointing to some Vite-related stuff in the node_modules folder.

I’ve tried messing with different versions of Vite and Node, but no luck. I’m pretty sure the fix is probably using an older version of something, but I’m not sure what.

Has anyone else run into this? Any ideas on how to fix it? I’d really appreciate any help!

hey ryan, i had a similar issue last month. try clearing your node_modules folder and package-lock.json, then run npm install again. that fixed it for me. if not, maybe check your vite config file for any weird settings? good luck!

I encountered this issue recently as well. It seems to be related to how ES modules handle directory imports. One solution that worked for me was updating the ‘type’ field in package.json to ‘module’. This tells Node.js to treat .js files as ES modules by default.

If that doesn’t resolve it, you might need to explicitly specify file extensions in your import statements. For example, change ‘import x from “./module”’ to ‘import x from “./module.js”’.

Lastly, ensure your Node.js version is compatible with the ES module features you’re using. I found that upgrading to Node.js 14+ resolved some similar directory import issues in my projects.