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

posts/vite-vue3-typescript/ #34

Open
utterances-bot opened this issue Jul 6, 2021 · 20 comments
Open

posts/vite-vue3-typescript/ #34

utterances-bot opened this issue Jul 6, 2021 · 20 comments
Labels
comment Article comment

Comments

@utterances-bot
Copy link

Building a Vue3 Typescript Environment with Vite | miyauci.me

Building a Typescript Vue3 environment using the No bundle tool Vite, along with ESLint and Prettier configuration to create a high DX environment.

https://miyauchi.dev/posts/vite-vue3-typescript/?utterances=8cc08b6fb9c2c533386c60bafrSa3H3e4ah8V%2BEUrswZK5CjMoTjXCs7C07Bn9GHZ0j4CY4jjajLKX5iLpzCYEWiOADy8aV%2B8LMKELdLdKf6NL%2BDYBMm1yJsanLdt%2FAeL69T18a7JnFuyGeWAxk%3D

Copy link

In config path alias, using '/@' work for me, not '/@/' (may be a typo).

@TomokiMiyauci
Copy link
Owner

Thanks for the comment!

This article is a bit old. It was correct at the time this article was written, but there have been changes.

I will update the entire article soon.

@TomokiMiyauci TomokiMiyauci added the comment Article comment label Jul 9, 2021
Repository owner deleted a comment from tonghoangvu Jul 9, 2021
@TomokiMiyauci
Copy link
Owner

I update latest

@DanielOaks
Copy link

Thank you for this article, it's very useful!

Just a note, right near the end it looks like the code block isn't closed properly, here:
https://github.com/TomokiMiyauci/me/blob/main/posts/vite-vue3-typescript/index.mdx#checking-template-statically-with-vue-tsc
(see the visible ```json:package.json at the bottom)

@TomokiMiyauci
Copy link
Owner

@DanielOaks Thanks for the comment!
I've fixed the article.

Copy link

Hello, thanks for the article.

Why the TS part is crossed ?
Is it because TS is used by vue ?

@TomokiMiyauci
Copy link
Owner

@JohnPAfr Thanks for the comment.

Why the TS part is crossed ?
Is it because TS is used by vue ?

The vite template now includes the TypeScript settings. Thus, the work in this section is no longer necessary.

Copy link

@TomokiMiyauci I've follow the article but I encountered a problem at the Path Alias part.

Module 'path' cannot be found in "import { resolve } from 'patht'". And also Same for __dirname in the resolve.

I'm on a Mac.

Any idea ?

@TomokiMiyauci
Copy link
Owner

@JohnPAfr You can try the following:

npm i -D @types/node
// or
yarn add -D @types/node

I need to update the article. Thanks for the report.

Copy link

Galex88 commented Sep 20, 2021

Hello !

First, thanks, it's a nice tutorial !

I have a little issue:
If I put "semi: true" in .prettierrc, eslint show me error (because I put a rule to have error on prettier issue) when there is a semi at the end of the line.
I followed ur tutorial for the eslint config, is there anything missing ?

Copy link

Galex88 commented Sep 20, 2021

Oh ! nevermind, I found the soluce.

It is needed to restart the eslint server in vs-code, and it did the trick.
Anyway, good job mate !

Copy link

When adding the line "@vue/prettier/@typescript-eslint" to the extends array in the aslant config file, I receive an error:

ESLint: Failed to load config "@typescript-eslint" to extend from. Referenced from: /path/to/project/.eslintrc.js. Please see the 'ESLint' output channel for details.

Is this a typo, or am I missing something? Thanks for putting together such a great article!

@TomokiMiyauci
Copy link
Owner

@jimmiejackson414
Can you show me the eslint config and package.json?

@jimmiejackson414
Copy link

@TomokiMiyauci sure thing!

.eslintrc.js:

module.exports = {
  root: true,
  env: {
    browser: true,
    es2021: true,
    node: true,
  },
  extends: [
    'plugin:vue/vue3-recommended',
    'eslint:recommended',
    '@vue/typescript/recommended',
    '@vue/prettier',
    '@vue/prettier/@typescript-eslint',
  ],
  parserOptions: {
    ecmaVersion: 2021,
  },
  plugins: [],
  rules: {},
};

package.json:

{
  "name": "vue3-vite-test",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc --noEmit && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "vue": "^3.2.25"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.10.1",
    "@typescript-eslint/parser": "^5.10.1",
    "@vitejs/plugin-vue": "^2.0.0",
    "@vue/eslint-config-prettier": "^7.0.0",
    "@vue/eslint-config-typescript": "^10.0.0",
    "eslint": "^8.7.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-vue": "^8.3.0",
    "prettier": "^2.5.1",
    "stylelint": "^14.3.0",
    "stylelint-config-recommended": "^6.0.0",
    "stylelint-config-standard": "^24.0.0",
    "typescript": "^4.4.4",
    "vite": "^2.7.2",
    "vue-tsc": "^0.29.8"
  }
}

@TomokiMiyauci
Copy link
Owner

@jimmiejackson414

Sorry for the inconvenience.There was a typo in the article.
@vue/prettier/@typescript-eslint is correctly prettier/@typescript-eslint.

Also, starting with eslint-config-prettier8.0.0, prettier/@typescript-eslint seems to have been merged into prettier.
https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md#version-800-2021-02-21

So all you have to do is just delete @vue/prettier/@typescript-eslint.

module.exports = {
  root: true,
  env: {
    browser: true,
    es2021: true,
    node: true,
  },
  extends: [
    'plugin:vue/vue3-recommended',
    'eslint:recommended',
    '@vue/typescript/recommended',
    '@vue/prettier',
  ],
  parserOptions: {
    ecmaVersion: 2021,
  },
  plugins: [],
  rules: {},
};

@jimmiejackson414
Copy link

Ah perfect, thank you so much!

Copy link

LapassetAlexis commented Feb 4, 2022

Hello and thanks for your work !

I have just a little issue with next command :

npm run prettier -w -u .

I have the following result :

npm ERR! No workspaces found:
npm ERR!   --workspace=-u

My package.json :

{
  "name": "yggtorrentchecker",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc --noEmit && vite build",
    "preview": "vite preview",
    "lint:script": "eslint --ext .ts,vue --ignore-path .gitignore .",
    "lint:markup": "vue-tsc --noEmit"
  },
  "dependencies": {
    "vue": "^3.2.25"
  },
  "devDependencies": {
    "@types/node": "^17.0.14",
    "@typescript-eslint/eslint-plugin": "^5.10.2",
    "@typescript-eslint/parser": "^5.10.2",
    "@vitejs/plugin-vue": "^2.0.0",
    "@vue/eslint-config-prettier": "^7.0.0",
    "@vue/eslint-config-typescript": "^10.0.0",
    "autoprefixer": "^10.4.2",
    "eslint": "^8.8.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-tailwindcss": "^3.4.3",
    "eslint-plugin-vue": "^8.4.1",
    "husky": "^7.0.4",
    "lint-staged": "^12.3.3",
    "postcss": "^8.4.6",
    "prettier": "^2.5.1",
    "tailwindcss": "^3.0.18",
    "typescript": "^4.4.4",
    "vite": "^2.7.2",
    "vue-tsc": "^0.29.8"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{ts,vue}": "eslint --fix",
    "*": "prettier -w -u"
  }
}

@TomokiMiyauci
Copy link
Owner


npm: 7.24.0

Try the following command.

npm exec -- prettier -w -u . 

It seems that npm run only executes the script field of package.json.
For more information about npm exec, please see https://docs.npmjs.com/cli/v8/commands/npm-exec.

@LapassetAlexis
Copy link

Super !

Thanks a lot !

Copy link

nice article. i have a issue. use tsx to write Component, the vscode show some errors:
Button.tsx:

const style = {
  width: '200px',
  height: '37px',
}
const Button = defineComponent({
  setup(props, { slots }) {
    console.log('*****slots')
    console.log(slots)
    const { default: _default, left, right } = slots
    return () => (
      <button style={style}>
        {left ? left() : null}
        {_default ? _default() : 'BUTTON'}
        {right ? right() : null}
      </button>
    )
  },
})

export default Button

error:
This JSX tag's 'children' prop expects a single child of type 'ReactNode', but multiple children were provided.ts(2746)

my tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2015",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "allowJs": true,
    "strict": false,
    "jsx": "preserve",
    "typesRoot": ["./node_modules/@types", "./types"],
    "sourceMap": true,
    // "strictNullChecks": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "lib": ["ESNext", "DOM"],
    "skipLibCheck": true,
    "baseUrl": "src",
    "paths": {
      "@/*": ["./*"],
      "#c": ["./components/index"]
    }
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.d.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "src/**/*.js",
    "auto-imports.d.ts",
    "src/test-lit.js"
  ],
  "references": [{ "path": "./tsconfig.node.json" }]
}

How to fix it?

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

No branches or pull requests

9 participants