Hi,
I trying to make Moralis work in AWS Lambda using NodeJs16.
I use the ECMAScript syntax and it doesn’t work for me.
I followed the documentation:
import Moralis from 'moralis';
import { EvmChain } from '@moralisweb3/evm-utils';
I get the following error
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "SyntaxError: Cannot use import statement outside a module",
"reason": {
"errorType": "SyntaxError",
"errorMessage": "Cannot use import statement outside a module",
"stack": [
"/var/task/node_modules/moralis/lib.esm/index.js:1",
"import { Streams } from '@moralisweb3/streams';",
"^^^^^^",
"",
"SyntaxError: Cannot use import statement outside a module",
" at Object.compileFunction (node:vm:352:18)",
" at wrapSafe (node:internal/modules/cjs/loader:1033:15)",
" at Module._compile (node:internal/modules/cjs/loader:1069:27)",
" at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)",
" at Module.load (node:internal/modules/cjs/loader:981:32)",
" at Function.Module._load (node:internal/modules/cjs/loader:822:12)",
" at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:163:29)",
" at ModuleJob.run (node:internal/modules/esm/module_job:198:25)",
" at async Promise.all (index 0)",
" at async ESMLoader.import (node:internal/modules/esm/loader:385:24)"
]
},
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: SyntaxError: Cannot use import statement outside a module",
" at process.<anonymous> (file:///var/runtime/index.mjs:1194:17)",
" at process.emit (node:events:527:28)",
" at emit (node:internal/process/promises:140:20)",
" at processPromiseRejections (node:internal/process/promises:274:27)",
" at processTicksAndRejections (node:internal/process/task_queues:97:32)"
]
}
My package.json is as follow:
{
"name": "NFT Web gallery",
"description": "Dependencies for the Lambdas deployed by SAM",
"version": "0.0.1",
"private": true,
"type": "module",
"dependencies": {
"@moralisweb3/evm-utils": "^2.14.1",
"ethers": "^6.0.2",
"moralis": "^2.14.1",
"node-fetch": "^3.3.0"
},
"devDependencies": {
"jest": "^26.6.3"
},
"scripts": {
"test": "jest"
}
}
I used to have to hack around to declare it using import. After I saw that the documentation has been updated to use import I thought it would work easy but no.
Any help would be appreciated.
Best