@@ -29,6 +29,7 @@ import nullthrows from 'nullthrows';
2929import { ContentGraph } from '@parcel/graph' ;
3030import { createDependency } from './Dependency' ;
3131import { type ProjectPath , fromProjectPathRelative } from './projectPath' ;
32+ import { BROWSER_ENVS } from './public/Environment' ;
3233
3334type InitOpts = { |
3435 entries ?: Array < ProjectPath > ,
@@ -223,6 +224,10 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
223224 correspondingRequest : string ,
224225 ) {
225226 let depNodes = targets . map ( target => {
227+ // In library mode, all of the entry's symbols are "used"
228+ // In non-browser environments, exports may also be used (e.g. serverless request handlers).
229+ let includeAllSymbols =
230+ target . env . isLibrary || ! BROWSER_ENVS . has ( target . env . context ) ;
226231 let node = nodeFromDep (
227232 // The passed project path is ignored in this case, because there is no `loc`
228233 createDependency ( '' , {
@@ -233,14 +238,13 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
233238 env : target . env ,
234239 isEntry : true ,
235240 needsStableName : true ,
236- symbols : target . env . isLibrary
241+ symbols : includeAllSymbols
237242 ? new Map ( [ [ '*' , { local : '*' , isWeak : true , loc : null } ] ] )
238243 : undefined ,
239244 } ) ,
240245 ) ;
241246
242- if ( node . value . env . isLibrary ) {
243- // in library mode, all of the entry's symbols are "used"
247+ if ( includeAllSymbols ) {
244248 node . usedSymbolsDown . add ( '*' ) ;
245249 node . usedSymbolsUp . set ( '*' , undefined ) ;
246250 }
0 commit comments