Is anybody having this issue when running the Lamb...
# help
a
Is anybody having this issue when running the Lambdas locally?
Copy code
SyntaxError: Cannot use import statement outside a module
t
can you share some more code causing this issue?
a
Yeah so my project uses TS.. and I have this..
Copy code
import { commonContainer } from './container';
When I run
npm run build
all works fine, but when I run
npm run start
and hit the endpoint, I’m getting this error:
Copy code
import { commonContainer } from './container';
^^^^^^

SyntaxError: Cannot use import statement outside a module
t
Is there any other code in this file? Verifying it's
.ts
and can you show me your tsconfig?
a
Yeah my tsconfig it’s the same as the default, sending now.
Only thing i’ve added is the decorators stuff.
Copy code
{
  "compilerOptions": {
    "target": "ES2018",
    "module": "commonjs",
    "lib": [
      "es2018"
    ],
    "declaration": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": false,
    "inlineSourceMap": true,
    "inlineSources": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "include": [
    "lib",
    "src"
  ]
}
Yes, the TS file exists and has code.
t
I've seen this issue before but hard to debug without being able to poke around the repo. I don't think it's SST related though, just js headaches
a
Yeah the weird thing is the
build
works.
f
@Adrián Mouly, were you able to get the
import
to work?
a
No, not yet 😞
Not sure why it builds, but then start fails.
t
does it fail at the type checking step? Or after that?
a
It fails when I hit the API from Postman, for example.
Not before that.
Does
start
has a verbose mode? I can try that, because the logs doesn’t have much info.
f
so when u run
sst start
, all the Lambdas are bundled once up front.
it seems like that bundle worked.
a
Well, verbose doesn’t make a difference, but here is the console log…
Copy code
0427ac52-8e75-4f1b-ae64-c9e9831e0578 REQUEST yabbleLocal-tasks-findAll [src/services/tasks/findAll/findAll.handler] invoked by API GET /tasks
0427ac52-8e75-4f1b-ae64-c9e9831e0578 ERROR /Users/amouly/Projects/yabble/yabble-serverless/src/packages/common/index.ts:1
import { commonContainer } from './container';
^^^^^^
Copy code
SyntaxError: Cannot use import statement outside a module
    at Module._compile (internal/modules/cjs/loader.js:895:18)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/Users/amouly/Projects/yabble/yabble-serverless/src/services/tasks/findAll/findAll.ts:1:57)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
Yeah, exactly.
t
Oh interesting this is at runtime
a
Yeah, it’s at runtime, that’s what confuses me.
Something wrong with ES modules or something, not sure.
I’ve been following this project structure, as somebody else shared here: https://github.com/lukewyman/karaoke-backend-sst
f
hmm… a couple of thoughts: • do all functions fail when invoked in
start
? or just this one function? • does it fail if you don’t import from
'./container'
?
If you can narrow it down a bit, I can give it a try on my end and see if I can reproduce it.
a
Going to try some other endpoint.
But all of them uses the same import, basically.
This import it’s for my dependency-injection.
f
i see.. i’m trying to figure out if the issue is with this
./container.js
file
a
Well.
There is no JS.
In my code.
I have all TS… the JS might be generated by the framework, but not me.
t
Are you importing or loading a file at runtime?
a
No, it’s just a normal lambda with a bunch of
import
on the top.
a
Yeah I couldn’t get back to it yet, but going to try couple things.