Hi folks, do you know if there is a way to differentiate Node.js and Edge from a 3rd party package.json standpoint? Like exports: {node:foobar, edge: foobar-edge-friendly.js} ?
React has "poisoned" exports https://github.com/reactjs/rfcs/blob/main/text/0227-server-module-conventions.md#poisoned-imports for server components, but Next doesn't seem to have an edge vs node equivalent?
Just to elaborate : it's easy to add different "node" and "edge" export, the problem is about having Next.js to pick up the right one automatically during build. I am coding a debug package that is meant to be used in deeply nested code where you can't tell whether you are in an edge rendered page/middleware or Node.js, I'd be eager to load the right code automatically.
Currently I bypass the issue with a conditional import but this is not scalable and clumsy.
#Edge environment package export map
14 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
i think it is edge-light for Vercel Edge specifically https://runtime-keys.proposal.wintercg.org (i found this from inspecting edge-compatible packages released by Vercel).
interestingly we also have edge in @vercel/og: https://www.npmjs.com/package/@vercel/og?activeTab=code. so i think it's best to just do whatever @vercel/og does:
{
"exports": {
".": {
"edge": {
"types": "./dist/index.edge.d.ts",
"default": "./dist/index.edge.js"
},
"edge-light": {
"types": "./dist/index.edge.d.ts",
"default": "./dist/index.edge.js"
},
"browser": {
"types": "./dist/index.edge.d.ts",
"default": "./dist/index.edge.js"
},
"worker": {
"types": "./dist/index.edge.d.ts",
"default": "./dist/index.edge.js"
},
"workerd": {
"types": "./dist/index.edge.d.ts",
"default": "./dist/index.edge.js"
},
"import": {
"types": "./dist/index.node.d.ts",
"default": "./dist/index.node.js"
},
"node": {
"types": "./dist/index.node.d.ts",
"default": "./dist/index.node.js"
},
"default": "./dist/index.node.js"
},
"./package.json": "./package.json"
}
}
This PR implements edge-light as a main field for bundling edge functions as defined in https://runtime-keys.proposal.wintercg.org
Resolves EC-614
Feature
Implements an existing feature request o...
Finally found the same link at the same time it was hidden in the docs, much thanks!
I am giving it a shot, TS is not happy yet but might be my config
This seems not officially documented yet
Yeah it seems that "bundler" moduleResolution doesn't find the types then
ok my bad I need a nested export
first "."' default, then the runtime key
and also I need to use "Bundler" module resolution in the importing package
interesting