After developing and publishing a package to npm, the code snippet below represents how it starts:
import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";
export interface ...
export class controlplaneDependencies extends pulumi.ComponentResource {
...
The publication and installation processes are successful. However, when attempting to execute the code in a different index.ts
, an error occurs:
import * as aws from "@pulumi/aws";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at compileFunction (<anonymous>)
at Object.compileFunction (node:vm:353:18)
at wrapSafe (node:internal/modules/cjs/loader:1039:15)
at Module._compile (node:internal/modules/cjs/loader:1073:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Object.require.extensions.<computed> [as .ts] (/Users/cinto/public-cloud-operator/tests/aws/node_modules/ts-node/src/index.ts:431:14)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
This is how I am using the package:
import * as controlplane from "@bb/controlplane";
stackOutput=new controlplane.controlplaneDependencies("Install dependencies", {
Provider: awsProvider,
A solution for this issue is currently unknown. Attempts have been made by adding
"type": "module",
but they were unsuccessful.
Other trials involved:
const aws = require( "@hybrid-cloud/aws" )
However, accessing aws
within the interface was not possible.
If you have any ideas or suggestions, they would be greatly appreciated. Below is the content of tsconfig.json
:
{
"compilerOptions": {
"strict": true,
"strictPropertyInitialization": false,
"target": "ES6",
"module": "CommonJS",
"moduleResolution": "Node",
"sourceMap": true,
"declaration": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"lib": [
"es2019",
"es5",
"es6",
"dom",
"es2015.collection"
],
"outDir": "./bin"
},
"exclude": [
"node_modules"
]
}