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
Verify and document typescript + svelte-preprocessor working out of the box #161
Comments
Works like a charm https://github.com/dummdidumm/template Differences to the javascript version
// ...
import sveltePreprocess from 'svelte-preprocess';
import typescript from '@rollup/plugin-typescript';
// ...
plugins: [
svelte({
// ...
preprocess: sveltePreprocess(), // <--
}),
// ...
commonjs(),
typescript(), // <-- added below commonjs
// ... Caveats:
|
tried this and verified! |
Thanks for all your work! It seems that the file
The following {
"include": ["src/**/*"],
"exclude": ["node_modules/*"],
"compilerOptions": {
"target": "es2017",
"types": ["svelte"],
"moduleResolution": "node"
}
}
Source: https://codechips.me/how-to-use-typescript-with-svelte/ |
Interesting ... I didn't even need a |
I trying to use it with sapper and now I got this error.
|
The template was intended as a proof of concept that the IDE works out of the box with svelte. Things like |
Things are close to working with Sapper. There's two main issues:
I made a fork of Sapper that you can use to code in TypeScript until the above fixes get merged and released: sveltejs/sapper#760 (comment) |
@dummdidumm Thanks for your quick response 🙂 Unfortunately, the problem persist. This is my {
"name": "svelte-app",
"version": "0.0.1",
"scripts": {
"build": "npm install && rollup -c",
"dev": "npm install && rollup -c -w",
"start": "sirv public --single",
"lint": "eslint . --ext .js,.svelte; exit 0",
"lint-report": "eslint . --ext .js,.svelte -o ./.eslint-report.html -f html; exit 0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-node-resolve": "^7.0.0",
"@rollup/plugin-typescript": "^4.1.2",
"eslint": "^7.0.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-svelte3": "^2.7.3",
"rollup": "^1.20.0",
"rollup-plugin-livereload": "^1.0.0",
"rollup-plugin-svelte": "^5.0.3",
"rollup-plugin-terser": "^5.1.2",
"svelte": "^3.0.0",
"svelte-preprocess": "^3.8.0",
"tslib": "^2.0.0",
"typescript": "^3.9.5"
},
"dependencies": {
"page": "^1.11.6",
"sirv-cli": "^0.4.4"
}
} and the import svelte from "rollup-plugin-svelte";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import livereload from "rollup-plugin-livereload";
import { terser } from "rollup-plugin-terser";
import autoPreprocess from "svelte-preprocess";
import typescript from "@rollup/plugin-typescript";
const production = !process.env.ROLLUP_WATCH;
export default {
input: "src/main.js",
output: {
sourcemap: true,
format: "iife",
name: "app",
file: "public/build/bundle.js"
},
plugins: [
svelte({
// enable run-time checks when not in production
dev: !production,
// we'll extract any component CSS out into
// a separate file - better for performance
css: css => {
css.write("public/build/bundle.css");
},
preprocess: autoPreprocess()
}),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ["svelte"]
}),
commonjs(),
typescript(),
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload("public"),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
watch: {
clearScreen: false
}
};
function serve () {
let started = false;
return {
writeBundle () {
if (!started) {
started = true;
require("child_process").spawn("npm", ["run", "start", "--", "--dev"], {
stdio: ["ignore", "inherit", "inherit"],
shell: true
});
}
}
};
} |
I cannot reproduce the error myself. But looking at your |
@dummdidumm I bumped all dependencies to their latest version. I deleted my custom Error message:
Svelte VS Code extensions installed:
Others VS Code extensions installed:
{
"name": "svelte-app",
"version": "0.0.1",
"scripts": {
"build": "npm install && rollup -c",
"dev": "npm install && rollup -c -w",
"start": "sirv public --single",
"lint": "eslint . --ext .js,.svelte; exit 0",
"lint-report": "eslint . --ext .js,.svelte -o ./.eslint-report.html -f html; exit 0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^13.0.0",
"@rollup/plugin-node-resolve": "^8.0.1",
"@rollup/plugin-typescript": "^4.1.2",
"eslint": "^7.2.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-svelte3": "^2.7.3",
"rollup": "^2.15.0",
"rollup-plugin-livereload": "^1.3.0",
"rollup-plugin-svelte": "^5.2.2",
"rollup-plugin-terser": "^6.1.0",
"svelte": "^3.23.1",
"svelte-preprocess": "^3.9.7",
"tslib": "^2.0.0",
"typescript": "^3.9.5"
},
"dependencies": {
"page": "^1.11.6",
"sirv-cli": "^0.4.6"
}
}
import svelte from "rollup-plugin-svelte";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import livereload from "rollup-plugin-livereload";
import { terser } from "rollup-plugin-terser";
import autoPreprocess from "svelte-preprocess";
import typescript from "@rollup/plugin-typescript";
const production = !process.env.ROLLUP_WATCH;
export default {
input: "src/main.js",
output: {
sourcemap: true,
format: "iife",
name: "app",
file: "public/build/bundle.js"
},
plugins: [
svelte({
dev: !production,
css: css => {
css.write("public/build/bundle.css");
},
preprocess: autoPreprocess()
}),
resolve({
browser: true,
dedupe: ["svelte"]
}),
commonjs(),
typescript(),
!production && serve(),
!production && livereload("public"),
production && terser()
],
watch: {
clearScreen: false
}
};
function serve () {
let started = false;
return {
writeBundle () {
if (!started) {
started = true;
require("child_process").spawn("npm", ["run", "start", "--", "--dev"], {
stdio: ["ignore", "inherit", "inherit"],
shell: true
});
}
}
};
}
const autoPreprocess = require("svelte-preprocess");
module.exports = {
preprocess: [
autoPreprocess()
]
}; |
@elvticc I've got the same problem. To fix it, I have :
I know, dummdidumm said |
Very interesting, seems like there is still some Vodoo to these setups - glad you got it working anyway! I will head over to the core svelte repo to discuss creating an official typescript template there. |
@AlexandreCantin @elvticc If you look at the repo, one of the things you'll notice is that there's a Typescript file in the I was running into the same error, Typescript saying no sources found. I tried changing it to What does work is just creating an Edit: After some experimentation, here is every combination that works:
{
"compilerOptions": {
"target": "ES2015 (or greater)",
"module": "ES2015, ES2020, or ESNEXT"
}
} |
Thanks for the investigation @GavinRay97 ! I updated the template. |
We think you can make a svelte project and just include the node modules for svelte-preprocessor to get
lang='ts'
support working. Verify that works and add some notes 👍The text was updated successfully, but these errors were encountered: