@@ -53,11 +53,20 @@ const copyHandlerDependencies = async (ctx: PluginContext) => {
5353 )
5454 }
5555
56+ // We need to create a package.json file with type: module to make sure that the runtime modules
57+ // are handled correctly as ESM modules
58+ promises . push (
59+ writeFile (
60+ join ( ctx . serverHandlerRuntimeModulesDir , 'package.json' ) ,
61+ JSON . stringify ( { type : 'module' } ) ,
62+ ) ,
63+ )
64+
5665 const fileList = await glob ( 'dist/**/*' , { cwd : ctx . pluginDir } )
5766
5867 for ( const filePath of fileList ) {
5968 promises . push (
60- cp ( join ( ctx . pluginDir , filePath ) , join ( ctx . serverHandlerDir , '.netlify' , filePath ) , {
69+ cp ( join ( ctx . pluginDir , filePath ) , join ( ctx . serverHandlerRuntimeModulesDir , filePath ) , {
6170 recursive : true ,
6271 force : true ,
6372 } ) ,
@@ -85,13 +94,6 @@ const writeHandlerManifest = async (ctx: PluginContext) => {
8594 )
8695}
8796
88- const writePackageMetadata = async ( ctx : PluginContext ) => {
89- await writeFile (
90- join ( ctx . serverHandlerRootDir , 'package.json' ) ,
91- JSON . stringify ( { type : 'module' } ) ,
92- )
93- }
94-
9597const applyTemplateVariables = ( template : string , variables : Record < string , string > ) => {
9698 return Object . entries ( variables ) . reduce ( ( acc , [ key , value ] ) => {
9799 return acc . replaceAll ( key , value )
@@ -136,13 +138,12 @@ export const clearStaleServerHandlers = async (ctx: PluginContext) => {
136138 */
137139export const createServerHandler = async ( ctx : PluginContext ) => {
138140 await tracer . withActiveSpan ( 'createServerHandler' , async ( ) => {
139- await mkdir ( join ( ctx . serverHandlerDir , '.netlify' ) , { recursive : true } )
141+ await mkdir ( join ( ctx . serverHandlerRuntimeModulesDir ) , { recursive : true } )
140142
141143 await copyNextServerCode ( ctx )
142144 await copyNextDependencies ( ctx )
143145 await copyHandlerDependencies ( ctx )
144146 await writeHandlerManifest ( ctx )
145- await writePackageMetadata ( ctx )
146147 await writeHandlerFile ( ctx )
147148
148149 await verifyHandlerDirStructure ( ctx )
0 commit comments