Rollup error `Could not resolve` TS files without extension (`.ts`) from Svelte files
See original GitHub issueWhat 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
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8
Top Results From Across the Web
Svelte: imported TypeScript files not recognized - Stack Overflow
I am trying to build an app with Svelte and TypeScript using Rollup and when I try to build my Svelte components I...
Read more >TypeScript support in Svelte - Learn web development
js files to .ts files and they will just work. Our TypeScript code will be able to run everywhere JavaScript can run. How...
Read more >Configuration • Docs • SvelteKit
Your project's configuration lives in a svelte.config.js file at the root of your project. As well as SvelteKit, this config object is used...
Read more >An import path cannot end with a '.ts' extension in TS
The error "An import path cannot end with a '.ts' extension" occurs when we include the extension when importing TypeScript files. To solve...
Read more >Imports - Astro Documentation
ts and .tsx file extensions should not be used when importing TypeScript files. Instead, either use .js / .jsx file extensions or completely ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
With
@rollup/plugin-node-resolve
listing all three of['.js', '.ts', '.svelte']
in itsextensions
config option solves this problem.Switched to SvelteKit and rollup-plugin-ts