I get the error ``` import * as gcp from '@pulu...
# typescript
I get the error
Copy code
import * as gcp from '@pulumi/gcp'

    SyntaxError: Cannot use import statement outside a module
from a
saved in Github repo. What am I missing?
looks like you’re using code that’s not been transpiled
isn’t valid in node unless the file is an
file and you’re in node 13 or newer
are you importing the wrong file, maybe?
which dependency is it?
It’s simply one Typescript file (our own, private module). Yes, the file transpiled to Javascript is
d, i.e. not in the Github repo. That could explain why it works locally. You know what the best-practice is?
it might still be included in the published package even if it’s ignored 🙂
you can’t import a typescript module unless you transpile things inside node_modules, and that usually makes your build extremely slow
so you want to transpile the module when you publish it and change your package.json
field to point to the transpiled code
or something
I see. The first (transpiling on each build) would require this in
, or?
Copy code
"scripts": {
        "build": "tsc"
(taken from https://github.com/pulumi/pulumi-gcp/blob/master/sdk/nodejs/package.json#L12-L14) The other way would be to push also the transpiled JS file to the Github repo.
Hmm, the
Copy code
"scripts": {
    "build": "tsc",
    "prepare": "npm run build"
doesn’t work, either. (The
part is from https://www.reddit.com/r/typescript/comments/9ctsbd/how_do_i_publish_a_typescript_library_to_a/e5db0e4/)
sorry, I had to go do other stuff
how do you reference the dependency? is it published on an internal npm server? or are you working with a monorepo type deal?
@broad-helmet-79436 No worries. Thanks for your help so far. I want to avoid to use a (private) NPM server (no matter the official or an internal server). I.e. to reference the dependency via
. Seems like pushing the transpiled JavaScript code is the way to go, as you mentioned. Others take the same approach: https://stackoverflow.com/questions/55002806/how-to-publish-a-private-typescript-npm-package-in-git/55004794#55004794
👍 1