fresh-spring-82225
02/20/2024, 8:15 PMimport * as fs from 'fs'
^^^^^^
SyntaxError: Cannot use import statement outside a module
Is there a trick I can use to get pulumi to import .ts files (with es6 module imports) from node_modules? I've tried fiddling with various tsconfig settings, but I haven't found one that works.little-cartoon-10569
02/20/2024, 8:34 PMlittle-cartoon-10569
02/20/2024, 8:37 PMruntime:
name: nodejs
options:
nodeargs: "--loader ts-node/esm --no-warnings --experimental-specifier-resolution=node"
fresh-spring-82225
02/20/2024, 10:47 PMshared.ts
in the base project directory without any changes (like nodeargs
), but if that file is in node_modules/.../shared.ts
, it fails
• I tried adding nodeargs
as you suggested, but got
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../node_modules/ts-node/esm'
• I added ts-node
as an explicit dependency (to get a newer version than what pulumi depends on), but then got
ReferenceError: require is not defined in ES module scope, you can use import instead
when importing pulumi libraries from shared.ts
....little-cartoon-10569
02/20/2024, 11:03 PMfresh-spring-82225
02/20/2024, 11:23 PMlittle-cartoon-10569
02/20/2024, 11:43 PMlittle-cartoon-10569
02/20/2024, 11:45 PM"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
And something along these lines in your package.json:
"type": "module",
"module": "esnext",
"target": "es2020",
fresh-spring-82225
02/21/2024, 4:35 PMvictorious-church-57397
02/23/2024, 8:39 PMvictorious-church-57397
02/23/2024, 8:39 PMfresh-spring-82225
02/23/2024, 10:21 PMvictorious-church-57397
02/24/2024, 9:25 AMfresh-spring-82225
02/25/2024, 1:34 AMtsc
after each change to my shared libraryvictorious-church-57397
02/27/2024, 9:08 PM