Search code examples
typescriptsnowpack

Snowpack Typescript Imports


I'm running Snowpack and I have a Typescript package (hosted on Github packages) that I want to pull in via

import SomeClass from '@myRepo/lib'

however I'm getting the error

"/_snowpack/pkg/@myRepo.SomeClass.ts" is not a constructor

When I copy-paste the class to a local file and import it using local imports (like below), it works.

import SomeClass from './lib'

Solution

  • Turns out this was more to do with my understanding (or lack thereof) on Typescript development.

    There were two things: First, I was incorrectly referencing a Typescript file in the main value of my package.json. Second, I hadn't correctly configured the build of my lib with appropriate .d.ts files.

    My package.json ended up needing to look like this

    ...    
    main: "dist/SomeClass.js",
    types: "dist/SomeClass.d.ts",
    ...