sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.09k stars 129 forks source link

Esbuild Plugin Error Using @anatine/esbuild-decorators #396

Open yotamishak opened 1 month ago

yotamishak commented 1 month ago

Hello,

using sst - 0.0.359

I can also confirm i get the same error with https://github.com/thomaschaaf/esbuild-plugin-tsc

while trying to get a POC running Nestjs in ion to potentially replace serverless framework.

We currently use Nestjs on serverless framework, using esbuild using the following esbuild config

 esbuild: {
      bundle: true,
      minify: false,
      sourcemap: true,
      target: 'node20',
      platform: 'node',
      concurrency: 10,

      packager: 'pnpm',
      exclude: [
        '@aws-sdk/*',
        '@nestjs/microservices',
        'pg-native',
        'nats',
        'mqtt',
        'kafkajs',
        'grpc',
        'apollo-server-express',
        'apollo-server-fastify',
        'class-transformer/storage',
        'cache-manager',
        '@nestjs/websockets/socket-module',
        'class-transformer',
        'class-validator',
      ],
      plugins: 'esbuild.plugins.js',
    },

esbuild.plugins.js

const { esbuildDecorators } = require('@anatine/esbuild-decorators');

const esbuildPlugins = [esbuildDecorators()];

module.exports = esbuildPlugins;

using nodejs install i was able to replicate the exclude functionality above sst.config.ts

///
import { esbuildDecorators } from '@anatine/esbuild-decorators';

export default $config({
  app(input) {
    return {
      name: 'nest-ion',
      removal: input?.stage === 'production' ? 'retain' : 'remove',
      home: 'aws',
    };
  },
  async run() {
    const api = new sst.aws.ApiGatewayV2('MyApi');
    api.route('ANY /{proxy+}', {
      handler: 'src/index.handler',
      nodejs: {
        install: [
          '@nestjs/microservices',
          'pg-native',
          'nats',
          'mqtt',
          'kafkajs',
          'grpc',
          'apollo-server-express',
          'apollo-server-fastify',
          'class-transformer/storage',
          'cache-manager',
          '@nestjs/websockets/socket-module',
          'class-transformer',
          'class-validator',
        ],
        esbuild: {
          plugins: [esbuildDecorators()],
        },
      },
    });
  },
});

but when i run sst dev (while try to use the esbuild plugin) i get the following error

~ Deploying

| Error ReferenceError: __filename is not defined in ES module scope
| at isFileSystemCaseSensitive (file:///Users/yotam/dev/nest-ion/node_modules/.pnpm/typescript@4.9.5/node_modules/typescript/lib/typescript.js:7301:45)
| at getNodeSystem (file:///Users/yotam/dev/nest-ion/node_modules/.pnpm/typescript@4.9.5/node_modules/typescript/lib/typescript.js:7066:45)
| at file:///Users/yotam/dev/nest-ion/node_modules/.pnpm/typescript@4.9.5/node_modules/typescript/lib/typescript.js:7535:19
| at file:///Users/yotam/dev/nest-ion/node_modules/.pnpm/typescript@4.9.5/node_modules/typescript/lib/typescript.js:7542:5
| at node_modules/.pnpm/typescript@4.9.5/node_modules/typescript/lib/typescript.js (file:///Users/yotam/dev/nest-ion/node_modules/.pnpm/typescript@4.9.5/node_modules/typescript/lib/typescript.js:7557:1)
| at __require2 (file:///Users/yotam/dev/nest-ion/.sst/platform/eval/eval-1715262938079.mjs:24:50)
| at node_modules/.pnpm/@anatine+esbuild-decorators@0.2.19_esbuild@0.21.1/node_modules/@anatine/esbuild-decorators/src/lib/esbuild-decorators.js (file:///Users/yotam/dev/nest-ion/node_modules/.pnpm/@anatine+esbuild-decorators@0.2.19_esbuild@0.21.1/packages/esbuild-decorators/src/lib/esbuild-decorators.ts:4:1)
| at __require2 (file:///Users/yotam/dev/nest-ion/.sst/platform/eval/eval-1715262938079.mjs:24:50)
| at node_modules/.pnpm/@anatine+esbuild-decorators@0.2.19_esbuild@0.21.1/node_modules/@anatine/esbuild-decorators/src/index.js (file:///Users/yotam/dev/nest-ion/node_modules/.pnpm/@anatine+esbuild-decorators@0.2.19_esbuild@0.21.1/packages/esbuild-decorators/src/index.ts:1:1)
| at __require2 (file:///Users/yotam/dev/nest-ion/.sst/platform/eval/eval-1715262938079.mjs:24:50)
yotamishak commented 1 month ago

i created a reproducible example without all the nestjs noise.

https://github.com/yotamishak/ion-esbuild-decorators