Closed ctjlewis closed 2 years ago
👷 Deploy request for useshoppingcart pending review. Visit the deploys page to approve it
🔨 Explore the source changes: 49aa1d1de192cce1522ef73cb091fb0230cc4248
Originally, I was just going to map any fallback export ./*
to ./*.js
, but the majority of the code is actually emitted TS output in dist/
, so I updated such that:
./utilites/*
maps to ./utilities/*.js
./*.js
maps to ./dist/*.js
Also, what's sneaky is that TypeScript will act like it's a valid import, but Node will (correctly) throw at runtime:
Failed to compile
./src/pages/api/checkout_sessions/cart.ts:12:0
Module not found: Package path ./utilities/serverless.js is not exported from package /home/christian/PersonalProjects/tezeta/node_modules/use-shopping-cart (see exports field in /home/christian/PersonalProjects/tezeta/node_modules/use-shopping-cart/package.json)
10 | */
11 | import inventory from "../../../../data/products.json";
> 12 | import { validateCartItems } from "use-shopping-cart/utilities/serverless.js";
If there were no exports
field, it would resolve okay, because ESM resolution would just let you specify the full entry point. But when you add exports
, ESM resolution defers 100% to it, and it's impossible to import entry points which aren't specified there.
Thank you @ctjlewis !!!
import { validateCartItems } from 'use-shopping-cart/utilities/serverless'
still doesn't work on my end
Version: 3.1.2
Hey @bryandandan, are you using TypeScript?
With TypeScript you have to import like this:
import { validateCartItems } from 'use-shopping-cart/utilities'
Sorry for the confusion!
This allows us to
import
orrequire
from any arbitrary entry point without breaking the overrides above it.Currently, for instance, it is not possible to do
import { validateCartItems } from 'use-shopping-cart/utilities/serverless'
. This is fixed by this PR.