Skip to content

Rollup error Could not resolve TS files without extension (.ts) from Svelte files #283

@TeemuKoivisto

Description

@TeemuKoivisto

What happens and why it is wrong

I am trying to bundle a Svelte project that uses TypeScript and while importing TS files from other TS files works well, importing TS files inside Svelte project requires setting the extension eg utils.ts which then causes linting errors. This works in other TS rollup bundlers, like rollup-plugin-ts, but since they have other issues I am hoping this gets fixed so I can keep using this plugin instead.

Environment

It's exactly this project https://github.com/TeemuKoivisto/svelte-tree-view/tree/master/core

Versions

Running the command didn't work but I extracted the versions manually.

"typescript": "^4.4.2"
"rollup": "^2.56.3",
"rollup-plugin-typescript2": "^0.30.0"

rollup.config.js

`rollup.config.js`:

tsconfig.json

`tsconfig.json`:
{
  "$schema": "https://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "moduleResolution": "node",
    "module": "es2020",
    "lib": [
      "es2020",
      "dom",
      "dom.iterable"
    ],
    "target": "es2019",
    "types": [
      "svelte",
      "jest",
      "@testing-library/jest-dom"
    ],
    /**
			svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
			to enforce using \`import type\` instead of \`import\` for Types.
			*/
    "importsNotUsedAsValues": "error",
    "allowSyntheticDefaultImports": true,
    "declaration": true,
    "declarationDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "noEmit": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true,
    /**
			To have warnings/errors of the Svelte compiler at the correct position,
			enable source maps by default.
			*/
    "sourceMap": true,
    "baseUrl": "."
  },
  "include": [
    "src/**/*.d.ts",
    "src/**/*.js",
    "src/**/*.ts",
    "src/**/*.svelte"
  ],
  "exclude": [
    "**/__tests__"
  ]
}

package.json

`package.json`:

plugin output with verbosity 3

plugin output with verbosity 3:
rpt2: plugin options:
{
    "verbosity": 3,
    "check": true,
    "clean": false,
    "cacheRoot": "xxx/svelte-tree-view/core/node_modules/.cache/rollup-plugin-typescript2",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {},
    "transformers": [],
    "tsconfigDefaults": {},
    "objectHashIgnoreUnknownHack": false,
    "cwd": "xxx/svelte-tree-view/core",
    "typescript": "version 4.4.2"
}
rpt2: rollup config:
{
    "external": [
        "@rollup/plugin-typescript",
        "rollup-plugin-typescript2"
    ],
    "input": "src/index.ts",
    "plugins": [
        {
            "name": "commonjs"
        },
        {
            "name": "rpt2"
        },
        {
            "name": "svelte"
        },
        {
            "name": "scss"
        },
        {
            "name": "node-resolve"
        },
        {
            "name": "terser"
        },
        {
            "name": "stdin"
        }
    ],
    "watch": {
        "clearScreen": false
    },
    "output": [
        {
            "file": "dist/index.js",
            "format": "umd",
            "name": "svelte-tree-view",
            "plugins": [],
            "sourcemap": true
        },
        {
            "file": "dist/index.es.js",
            "format": "es",
            "plugins": [],
            "sourcemap": true
        }
    ]
}
rpt2: tsconfig path: xxx/svelte-tree-view/core/tsconfig.json
rpt2: included:
[
    "*.ts+(|x)",
    "**/*.ts+(|x)"
]
rpt2: excluded:
[
    "*.d.ts",
    "**/*.d.ts"
]
(node:44909) [DEP0148] DeprecationWarning: Use of deprecated folder mapping "./" in the "exports" field module resolution of the package at xxx/svelte-tree-view/node_modules/rollup-plugin-typescript2/node_modules/tslib/package.json.
Update this package.json to use a subpath pattern like "./*".
(Use `node --trace-deprecation ...` to show where the warning was created)
rpt2: Ambient types:
rpt2:     xxx/svelte-tree-view/node_modules/@types/jest/index.d.ts
rpt2: ambient types changed, redoing all semantic diagnostics
rpt2: transpiling 'xxx/svelte-tree-view/core/src/index.ts'
rpt2:     cache: 'xxx/svelte-tree-view/core/node_modules/.cache/rollup-plugin-typescript2/rpt2_7f906861443330a2bc40777737066bec1b082c02/code/cache/ece56db94fb66ebecf2e8491d48273d1b7374a6b'
rpt2:     cache miss
rpt2:     cache: 'xxx/svelte-tree-view/core/node_modules/.cache/rollup-plugin-typescript2/rpt2_7f906861443330a2bc40777737066bec1b082c02/syntacticDiagnostics/cache/ece56db94fb66ebecf2e8491d48273d1b7374a6b'
rpt2:     cache miss
rpt2:     cache: 'xxx/svelte-tree-view/core/node_modules/.cache/rollup-plugin-typescript2/rpt2_7f906861443330a2bc40777737066bec1b082c02/semanticDiagnostics/cache/ece56db94fb66ebecf2e8491d48273d1b7374a6b'
rpt2:     cache miss
rpt2: generated declarations for 'xxx/svelte-tree-view/core/src/index.ts'
[!] Error: Could not resolve './tree-utils' from src/TreeView.svelte
Error: Could not resolve './tree-utils' from src/TreeView.svelte

Metadata

Metadata

Assignees

Labels

kind: regressionSpecific type of bug -- past behavior that worked is now brokenproblem: plugin orderThe plugin order in this issue seems incompatible. See the "Compatibility" section in the READMEproblem: staleIssue has not been responded to in some timescope: integrationRelated to an integration, not necessarily to core (but could influence core)solution: workaround availableThere is a workaround available for this issue

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions