Closed smasilamani-cfins closed 3 years ago
Hey, thanks for the report. I wonder if this is something with Typescript configuration? I can do simple:
import { createServer, proxy } from '@vendia/serverless-express';
console.log(createServer, proxy)
with my babel config and I get:
[Function: createServer] [Function: proxy]
The way the package is structured, it has an index.js
at the top-level https://github.com/vendia/serverless-express/blob/master/index.js that simply re-exports the index.js
in src/index.js
which is where those functions are defined.
If you run ls node_modules/@vendia/serverless-express
what do you get (is the index.js there)?
I just tried with basic TypeScript by running:
npx tsc lambda.ts
node lambda.js
And I got the same [Function: createServer] [Function: proxy]
output.
If you don't want to spend time figuring out what's going on (why the top-level index.js isn't exporting src/index.js) you can simply import like import { createServer, proxy } from '@vendia/serverless-express/src'
, however, this isn't guaranteed to continue to work forever (though it's unlikely we'll change/break it)
Thank you for getting back on this quickly, here is my tsconfig.json and we do not use babel at all.
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"target": "ES2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": ".",
"incremental": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"lib": ["ES2019"],
"skipLibCheck": true,
"alwaysStrict": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"strict": false,
"paths": {
"@app/*": ["src/app/*"],
"@clearance/*": ["src/clearance/*"],
"@submission/*": ["src/submission/*"],
"@shared/*": ["src/shared/*"],
"@external_services/*": ["src/external_services/*"]
}
},
"exclude": ["node_modules", ".serverless", ".webpack", "_warmup", ".vscode", "dist"]
}
ls command :
$ ls -ltr node_modules/@vendia/serverless-express
total 28
-rwxrwxrwx 1 root root 5161 Oct 26 1985 README.md
-rwxrwxrwx 1 root root 3609 Oct 26 1985 package.json
-rwxrwxrwx 1 root root 59 Oct 26 1985 middleware.js
-rwxrwxrwx 1 root root 11357 Oct 26 1985 LICENSE
-rwxrwxrwx 1 root root 54 Oct 26 1985 index.js
-rwxrwxrwx 1 root root 2508 Oct 26 1985 CHANGELOG.md
drwxrwxrwx 1 root root 4096 Jan 4 17:59 src
Without running my copy command all I can see is undefined (last line in the output) Code:
import { Handler } from 'aws-lambda';
import Express from 'express';
import { Server } from 'http';
import { INestApplication } from '@nestjs/common';
import { ExpressAdapter } from '@nestjs/platform-express';
import { DSServerConstants } from '@shared/models/server.constants';
import { createServer, proxy } from '@vendia/serverless-express';
import { bootstrap } from './main';
console.log(createServer, proxy);
Output:
offline: Offline [http for lambda] listening on http://localhost:3002
offline: Function names exposed for local invocation by aws-sdk:
* index: ds-iq-submission-service-local-index
┌─────────────────────────────────────────────────────────────────────────┐
│ │
│ ANY | http://localhost:3003/local │
│ POST | http://localhost:3003/2015-03-31/functions/index/invocations │
│ ANY | http://localhost:3003/local/{proxy*} │
│ POST | http://localhost:3003/2015-03-31/functions/index/invocations │
│ │
└─────────────────────────────────────────────────────────────────────────┘
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/hiberfil.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/pagefile.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/swapfile.sys'
offline: [HTTP] server ready: http://localhost:3003 �
offline:
offline: Enter "rp" to replay the last request
asset src/index.js 22.9 MiB [emitted] (name: src/index) 1 related asset
cached modules 20 MiB [cached] 3590 modules
runtime modules 1.03 KiB 5 modules
./node_modules/agentkeepalive/index.js 169 bytes [code generated]
webpack compiled successfully in 3486 ms
Serverless: Watching for changes...
No issues found.
offline: ANY /local/api-json (λ: index)
undefined undefined
Since my copy command works fine, we should be good for now and when I get time, I can look into it in detail.
Thanks again.
Hello
We are using this package for one for our serverless typescript projects and have been facing issue with the import. During runtime none of the imports from this package are resolving and we have to do a patch to make it work, Please find below the respective code and error we get unless we run the below command after npm install. Please advise.
Command to fix :
cp -r ./node_modules/@vendia/serverless-express/src/*.js ./node_modules/@vendia/serverless-express
If we run the above command after npm install, then it works fine.
Error:
Webpack:
Code: (only the interested part)