Hey there does anyone have advice how to configur...
# general
Hey there does anyone have advice how to configure package/tsconfig .json files so that i can
npm install
a pulumi repo via a github url? I keep getting error
SyntaxError: Cannot use import statement outside a module
when running pulumi in the repo that installed the pulumi package. It seems i may need to set the “main” field in package.json to point to the compiled entrypoint .js file. However, that then messes up pulumi when i try and run it locally from the repo. As now pulumi tries to invoke the index.js file instead of the index.ts file. I’m trying to mimic how an installed pulumi npm module works. There are .js, .js.map, and .d.ts files. No .ts files. I’m not sure how to replicate this so that the install via github url works, as well as running pulumi within the pulumi pkg repo itself (I do that for testing) I can’t figure this out 🙂 Any advice would be much appreciated
pulumi uses a
to load the program. This means that all the code which is used must use commonJs and not newer es6 modules. I suspect that the package you are trying to use has not been compiled to commonJs - do you have
"compilerOptions.module": "commonjs"
set in the module you are trying to import? When you say "import a pulumi repo via a github url", are you trying to import the source code? In which can you probably need to build a package and import that (you could use github packages for this)
Thanks for replying Mark! Yes my module setting is commonjs I am trying to import the local source code into another local repo via an npm install with a git url.
Is there no way to do this without packaging up the pulumi repo to npm or github pkgs?
Even if i do pkg it up, i need to set “main” in package.json to be
, right? Otherwise pulumi won’t be able to run the installed pkg.
What is the proper development flow then? Bec i’d like to test my pulumi code within the repo itself. Do i need something like nodemon that is going to run tsc on changes? It seems redundant to need this. Pulumi is able to have a .ts file as an entrypoint
Pulumi won't build the code in the module you are installing, so this needs to be built before you do the install. The easiest way to do this is to publish a package with build code from your other repository and then import that. (As an alternative you may be able to use a npm install script to run tsc on the package when it is installed. I have not tried this though) My workflow is to create ComponentResource components in other repositories and publish them as GitHub packages. In these repositories I have an
folder where I have a Pulumi program which can create these resources for testing purposes. I then install these packages into other repositories which use these components in different environments. The advantage of this approach is I can keep my components versioned and easily track updates to the environments. The downside is lots of building of packages which can be tedious at times. If you wanted to just reference the source code, you could probably use git submodules to bring the code into the current repository. I have never really got my head around those though and always seen to end up in a mess. YMMV though.
Looking at the docs for npm install - https://docs.npmjs.com/cli/v7/commands/npm-install - it looks like you may be able to add a
script that npm will run when you do an
for a git url. This could run
to build the code from the repository so that Pulumi can use it.
Thanks Mark 😃. I ended up doing the postinstall script. And just installing the module via a git url. Soon I will actually publish to npm.
great to hear it worked... Something I may use in the future - would be a good way of speeding up workflow