spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.97k stars 184 forks source link

Module '"spacetime"' has no exported member 'Spacetime'. Did you mean to use 'import Spacetime from "spacetime"' instead? #407

Closed antonstefer closed 4 months ago

antonstefer commented 5 months ago

Setup

package.json:

{
    "type": "module"
    "dependencies" : {
        "spacetime": "7.5.0",
        "typescript": "5.0.4"
    }
}

tsconfig.json:

{
    "extends": "@tsconfig/node20/tsconfig.json",
    "compilerOptions": {
        "lib": ["es2023"],
        "module": "node16",
        "moduleResolution": "node16"
        "target": "es2022",

        "strict": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "useUnknownInCatchVariables": false,
        "noUnusedLocals": true,
        "resolveJsonModule": true,

        "outDir": "dist/",
        "baseUrl": ".",
        "verbatimModuleSyntax": true
    },
    "exclude": ["node_modules"],
}

Problem

Importing Spacetime like this:

import type { Spacetime } from 'spacetime'
import spacetime from 'spacetime'

produces the following Typescript error:

TS2614: Module '"spacetime"' has no exported member 'Spacetime'. Did you mean to use 'import Spacetime from "spacetime"' instead?

Directly importing from spacetime/types/types like mentioned here does not work as well:

TS2307: Cannot find module 'spacetime/types/types' or its corresponding type declarations.

Is there another way to import the types or is something broken? This syntax has been working when my project was still using CommonJS.

Thank you!

jecraig commented 5 months ago

Can you create a small repo that recreates this issue.

antonstefer commented 5 months ago

Here you go: https://github.com/antonstefer/spacetime-import-issue

spencermountain commented 5 months ago

Thank you Anton! Will keep this open until it's released, in the next few days. cheers

spencermountain commented 4 months ago

released as 7.6.0 cheers!