Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'impliedNodeFormat') #39

Open
ZeeD opened this issue May 12, 2022 · 3 comments
Open

Comments

@ZeeD
Copy link

ZeeD commented May 12, 2022

Hi.
I'm working on a typescript project, and I'm using jest to run the tests.
I introduced ttypescript and ts-transform-paths but now I have a strange error: for each test I have an error with this message:

  ● Test suite failed to run

    TypeError: Cannot read properties of undefined (reading 'impliedNodeFormat')

      at Object.getModeForUsageLocation (node_modules/typescript/lib/typescript.js:114398:18)
      at resolveExternalModule (node_modules/typescript/lib/typescript.js:50141:90)
      at resolveExternalModuleNameWorker (node_modules/typescript/lib/typescript.js:50117:19)
      at getExternalModuleFileFromDeclaration (node_modules/typescript/lib/typescript.js:85790:32)
      at Object.getExternalModuleFileFromDeclaration (node_modules/typescript/lib/typescript.js:85629:36)
      at tryGetModuleNameFromDeclaration (node_modules/typescript/lib/typescript.js:29494:59)
      at Object.getExternalModuleNameLiteral (node_modules/typescript/lib/typescript.js:29458:20)
      at createRequireCall (node_modules/typescript/lib/typescript.js:103357:33)
      at visitImportDeclaration (node_modules/typescript/lib/typescript.js:103317:80)
      at topLevelVisitor (node_modules/typescript/lib/typescript.js:102966:28)

The error doesn't come up if I remove { "transform": "@zerollup/ts-transform-paths" } from compilerOptions.plugins

For reference this is the content of my tsconfig.json

{
    "compilerOptions": {
        "baseUrl": "src",
        "paths": {
            "@/*": ["*"],
            "@messages/*": ["messages/*"]
        },
        "module": "esnext",
        "declaration": true,
        "declarationMap": true,
        "downlevelIteration": true,
        "noImplicitAny": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "target": "es5",
        "noUnusedLocals": true,
        "skipLibCheck": true,
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "importHelpers": true,
        "esModuleInterop": true,
        "outDir": "./lib",
        "lib": ["dom", "es2017"],
        "experimentalDecorators": true,
        "plugins": [
            { "transform": "@zerollup/ts-transform-paths" },
            { "transform": "typescript-is/lib/transform-inline/transformer" }
        ]
    },
    "typedocOptions": {
        "entryPoints": ["src/index.ts", "src/config/index.ts", "src/errors/errors.ts"],
        "out": "docs",
        "theme": "markdown",
        "exclude": "src/messages",
        "entryPointStrategy": "resolve",
        "plugin": ["typedoc-plugin-markdown", "typedoc-plugin-merge-modules", "typedoc-plugin-rename-defaults"],
        "mergeModulesMergeMode": "module",
        "mergeModulesRenameDefaults": true,
        "includeVersion": true,
        "excludePrivate": true,
        "excludeNotDocumented": true,
        "readme": "none",
        "gitRevision": "main"
    },
    "include": ["src", "test"],
    "exclude": ["node_modules"]
}

and the jest.config.cjs

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
    globals: {
        'ts-jest': {
            compiler: 'ttypescript',
        },
    },
    preset: 'ts-jest',
    collectCoverageFrom: ['src/**', '!src/messages/**'],
    moduleNameMapper: {
        '^@/(.*)$': '<rootDir>/src/$1',
        '^@messages/(.*)$': '<rootDir>/src/messages/$1',
    },
    roots: ['src', 'test']
};

can you help me understanding what is going on?

@alixq
Copy link

alixq commented May 30, 2022

We have the same issue when upgrading to the latest TS versions

@fires3as0n
Copy link

I have tried different TS versions from 4.6 till 4.9 and have this issue with all of them

@fires3as0n
Copy link

I switched to https://www.npmjs.com/package/typescript-transform-paths, just had to edit the "paths" tsconfig setting, otherwise works the same just replace this abandoned plugin with that one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants