important-australia-24045
12/22/2022, 3:06 PMpulumi-beta
, I am using the following code to define my component resource:
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
export interface S3BucketArgs {
name: string;
}
export class S3Bucket extends pulumi.ComponentResource {
public readonly bucket: aws.s3.Bucket;
constructor(name: string, args: S3BucketArgs, opts?: pulumi.ComponentResourceOptions) {
super("my:modules:S3Bucket", name, {}, opts);
this.bucket = new aws.s3.Bucket(name, {
bucket: args.name,
}, { parent: this });
}
}
pulumi-alpha
, I installed the pulumi-beta
this package with the following command:
npm i git+<https://github.com/briancaffey/pulumi-beta.git>
Then I use it like this in `index.ts`:
import * as pulumi from "@pulumi/pulumi";
import { S3Bucket } from "pulumi-beta";
const bucket = new S3Bucket("my-bucket", {
name: "my-example-pulumi-bucket",
});
export const bucketName = bucket.bucket.id;
tsc
and I can see that it built the application in the bin
directory:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bucketName = void 0;
const pulumi_beta_1 = require("pulumi-beta");
const bucket = new pulumi_beta_1.S3Bucket("my-bucket", {
name: "my-example-pulumi-bucket",
});
exports.bucketName = bucket.bucket.id;
//# sourceMappingURL=index.js.map
pulumi preview
to see how things will look, but I get this error:
~/git/github/pulumi-alpha$ pulumi preview
Previewing update (dev)
View Live: <https://app.pulumi.com/briancaffey/pulumi-alpha/dev/previews/f8469d80-a9d5-4e95-9d9f-8a5830220f5c>
Type Name Plan Info
+ pulumi:pulumi:Stack pulumi-alpha-dev create 1 error
Diagnostics:
pulumi:pulumi:Stack (pulumi-alpha-dev):
error: Running program '/Users/brian/git/github/pulumi-alpha' failed with an unhandled exception:
/Users/brian/git/github/pulumi-alpha/node_modules/pulumi-beta/index.ts:1
import * as pulumi from "@pulumi/pulumi";
^^^^^^
SyntaxError: Cannot use import statement outside a module
pulumi-beta
repo, I added "type": "module",
to package.json
, pushed to GitHub, then reinstalled everything in `pulumi-alpha`:
rm -rf bin
rm -rf node_modules
rm package-lock.json
npm i
tsc
pulumi preview
again I get the same error as before:
Diagnostics:
pulumi:pulumi:Stack (pulumi-alpha-dev):
error: Running program '/Users/brian/git/github/pulumi-alpha' failed with an unhandled exception:
/Users/brian/git/github/pulumi-alpha/node_modules/pulumi-beta/index.ts:1
import * as pulumi from "@pulumi/pulumi";
^^^^^^
SyntaxError: Cannot use import statement outside a module
many-telephone-49025
12/22/2022, 3:13 PMimportant-australia-24045
12/22/2022, 3:14 PMmany-telephone-49025
12/22/2022, 3:31 PMIf your package has a main .js file, you will need to indicate the main declaration file in your package.json file as well. Set the types property to point to your bundled declaration file. For example:
{
"name": "awesome",
"author": "Vandelay Industries",
"version": "1.0.0",
"main": "./lib/main.js",
"types": "./lib/main.d.ts"
}
index.ts
when importedimportant-australia-24045
12/22/2022, 3:40 PMShould myIf your package has a main .js file,
pulumi-beta
reusable component resource have a main .js
file?many-telephone-49025
12/22/2022, 3:40 PMimportant-australia-24045
12/22/2022, 3:41 PM"main": "index.ts",
This is what I have in my pulumi-beta
package.jsonpulumi-alpha
repo (the pulumi project that consumes the pulumi-beta
component resource) "main": "index.ts",
many-telephone-49025
12/22/2022, 3:42 PM{
"name": "pulumi-beta",
"main": "./bin/index.js",
"types": "./bin/index.d.ts",
...
}
important-australia-24045
12/22/2022, 3:42 PMvictorious-church-57397
12/22/2022, 3:44 PMimportant-australia-24045
12/22/2022, 3:44 PMvictorious-church-57397
12/22/2022, 3:45 PM{
"name": "@jugo-io/jugo-pulumi-common",
"version": "1.0.0",
"description": "Jugo Common Pulumi Library",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"build": "npx tsc",
"lint": "node_modules/.bin/eslint .",
"lint:fix": "node_modules/.bin/eslint . --fix"
},
"repository": {
"type": "git",
"url": ""
},
"release": {
"branches": [
"main"
]
},
"publishConfig": {
"registry": "<https://npm.pkg.github.com>"
},
"files": [
"dist"
],
"peerDependencies": {
...
},
"author": "<mailto:jugo-admin+platform-team@gdsgroup.com|jugo-admin+platform-team@gdsgroup.com>",
"license": "MIT",
"devDependencies": {
...
}
}
important-australia-24045
12/22/2022, 3:45 PMimport * as pulumi from "@pulumi/pulumi";
^^^^^^
SyntaxError: Cannot use import statement outside a module
many-telephone-49025
12/22/2022, 3:46 PMvictorious-church-57397
12/22/2022, 3:47 PM{
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"declaration": true,
"outDir": "./dist"
},
"include": [
"src/**/*"
]
}
important-australia-24045
12/22/2022, 3:49 PMpulumi-beta
repovictorious-church-57397
12/22/2022, 3:50 PMimportant-australia-24045
12/22/2022, 3:50 PMvictorious-church-57397
12/22/2022, 3:50 PMimportant-australia-24045
12/22/2022, 3:51 PMSyntaxError: Cannot use import statement outside a module
in pulumi-beta
:
• add "declaration": true,
in tsconfig.json
• add "files": ["bin"]
(I’m using bin
where you are using dist
@victorious-church-57397. If I do this, then nothing is installed in node_modules
in when i run npm i
in pulumi-alpha
, since I am not committing the bin
directory to the repo on GitHubvictorious-church-57397
12/22/2022, 4:21 PMimportant-australia-24045
12/22/2022, 4:22 PMmany-telephone-49025
12/22/2022, 4:51 PMimportant-australia-24045
12/22/2022, 5:00 PMpulumi-alpha
when I do npm i
, it only has .ts
files and doesn't have any .js
files. I am not super experienced with typescript, but I think that is part of what is going on with the error message I am seeing.
Thank you for helping me to reproduce this 🙏build
script in package.json?clever-painter-96148
12/22/2022, 5:55 PMimportant-australia-24045
12/22/2022, 5:56 PMclever-painter-96148
12/22/2022, 5:57 PMimportant-australia-24045
12/22/2022, 5:57 PMclever-painter-96148
12/22/2022, 5:57 PMimportant-australia-24045
12/22/2022, 5:58 PM"postinstall": "tsc --outDir ./build"
clever-painter-96148
12/22/2022, 5:59 PMvictorious-church-57397
12/22/2022, 5:59 PMclever-painter-96148
12/22/2022, 6:00 PMMaybe it will be easier if I just publish to npm then, I guessI did that too. Working with multi repos and packages does the job. But that's still a lot of overhead compared to monorepos.
important-australia-24045
12/22/2022, 6:00 PMvictorious-church-57397
12/22/2022, 6:02 PMclever-painter-96148
12/22/2022, 6:04 PMvictorious-church-57397
12/22/2022, 6:05 PMclever-painter-96148
12/22/2022, 6:05 PMvictorious-church-57397
12/22/2022, 6:06 PMclever-painter-96148
12/22/2022, 6:06 PMvictorious-church-57397
12/22/2022, 6:06 PMimportant-australia-24045
12/22/2022, 6:16 PM~/git/github/pulumi-alpha$ pulumi preview
Previewing update (dev)
View Live: <https://app.pulumi.com/briancaffey/pulumi-alpha/dev/previews/f28c1725-f76e-4631-a26d-5fef4670eeca>
Type Name Plan
+ pulumi:pulumi:Stack pulumi-alpha-dev create
+ └─ my:modules:S3Bucket my-bucket create
+ └─ aws:s3:Bucket my-bucket create
Outputs:
bucketName: output<string>
Resources:
+ 3 to create
~/git/github/pulumi-alpha$
✨many-telephone-49025
12/22/2022, 6:17 PMimportant-australia-24045
12/22/2022, 6:17 PMbin
directory to my pulumi-alpha
repo @many-telephone-49025, this is because I’m installing directly from github. Then I removed "type": "module"
from the pulumi-beta
repo and it workedmany-telephone-49025
12/22/2022, 6:20 PMimportant-australia-24045
12/22/2022, 6:43 PMpulumi-alpha
victorious-church-57397
12/22/2022, 7:04 PMmany-telephone-49025
12/23/2022, 8:31 AMtypes
but you still have typings
in yor package.json
of pulumi-beta
! And it’s still working!