Problem with netlify-cli
. I created a extremely simple reproduction repository.
I’m using the new @netlify/functions
first-class typescript support feature. Love it (except for this problem), by the way, thanks!
The problem is, I’m importing a dependency, the official AWS S3 client @aws-sdk/client-s3
, and this is causing netlify dev
to break. Here’s the relevant code from the repro:
import { Handler } from '@netlify/functions';
import { S3 } from '@aws-sdk/client-s3';
const handler: Handler = async (event) => {
// Omitted: actually doing something with the S3 Client
// vvvv--- but this line causes `netlify dev` to break
const client = new S3({});
return {
statusCode: 200,
body: `Hello world`,
};
};
export { handler };
The error message reported by netlify-cli
is “Cannot find module 'exports'
” (full error message below).
NOTE: the function builds just fine on netlify and works, it’s just netlify-cli
chokes on it.
If I comment out the usage of the S3
imported function, the problem goes away (I presume because of esbuild tree-shaking or something).
I also made the recommended settings of esModuleInterop
and isolatedModules
in the tsconfig.json
file.
Again, there’s a super simple reproduction here:
Just clone, npm install, and run npm run dev
to see the issue. Thanks in advance for any help, and again, really love the first-class typescript support!
◈ Function builder zip-it-and-ship-it building functions from directory /netlify-cli-bug-repo/netlify/functions
◈ Function builder zip-it-and-ship-it finished building functions from directory /netlify-cli-bug-repo/netlify/functions
Error: In file "/netlify-cli-bug-repo/.netlify/functions-serve/test/test.js"
Cannot find module 'exports'
Require stack:
- /netlify-cli-bug-repo/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/resolve.js
- /netlify-cli-bug-repo/node_modules/@netlify/zip-it-and-ship-it/src/node_dependencies/index.js
- /netlify-cli-bug-repo/node_modules/@netlify/zip-it-and-ship-it/src/main.js
- /netlify-cli-bug-repo/node_modules/netlify/src/deploy/hash_fns.js
- /netlify-cli-bug-repo/node_modules/netlify/src/deploy/index.js
- /netlify-cli-bug-repo/node_modules/netlify/src/index.js
- /netlify-cli-bug-repo/node_modules/@netlify/config/src/api/client.js
- /netlify-cli-bug-repo/node_modules/@netlify/config/src/main.js
- /netlify-cli-bug-repo/node_modules/netlify-cli/src/utils/command.js
- /netlify-cli-bug-repo/node_modules/netlify-cli/src/commands/dev/index.js
- /netlify-cli-bug-repo/node_modules/@oclif/config/lib/plugin.js
- /netlify-cli-bug-repo/node_modules/@oclif/config/lib/config.js
- /netlify-cli-bug-repo/node_modules/@oclif/config/lib/index.js
- /netlify-cli-bug-repo/node_modules/@oclif/command/lib/command.js
- /netlify-cli-bug-repo/node_modules/@oclif/command/lib/index.js
- /netlify-cli-bug-repo/node_modules/netlify-cli/src/index.js
- /netlify-cli-bug-repo/node_modules/netlify-cli/bin/run
Code: MODULE_NOT_FOUND