async _preparePackageJson() {
    const runtime = this.serverless.service.provider.runtime || 'nodejs18.x'

    const { external, exclude } = await this._externals(runtime)

    const packageJson = await this._readPackageJson()

    const packageJsonNoDevDeps = {
      ...packageJson,
    }
    delete packageJsonNoDevDeps.devDependencies

    const buildProperties = await this._buildProperties()

    if (packageJson.dependencies) {
      if (buildProperties.packages !== 'external') {
        packageJsonNoDevDeps.dependencies = {}
        for (const key of external) {
          if (packageJson.dependencies[key]) {
            packageJsonNoDevDeps.dependencies[key] =
              packageJson.dependencies[key]
          }
        }
      }

      for (const key of exclude) {
        delete packageJsonNoDevDeps.dependencies[key]
      }
    }

    const packageJsonNoDevDepsStr = JSON.stringify(
      packageJsonNoDevDeps,
      null,
      2,
    )

    const packageJsonBuildPath = path.join(
      this.serverless.config.serviceDir,
      '.serverless',
      'build',
      'package.json',
    )

    await writeFile(packageJsonBuildPath, packageJsonNoDevDepsStr)

    const packager = this._determinePackager()

    await new Promise((resolve, reject) => {
      const child = spawn(packager, ['install'], {
        cwd: path.join(
          this.serverless.config.serviceDir,
          '.serverless',
          'build',
        ),
        shell: true,
      })
      child.on('error', (error) => {
        log.error('Error installing dependencies', error)
        reject(error)
      })

      child.on('close', (code) => {
        resolve(code)
      })
    })
  }
Take the package.json and add an updated version with no dev dependencies and external and excluded node_modules taken care of, to the .serverless/build directory