実現したいこと
ご覧いただき、誠にありがとうございます。
vue@3.5.17
で、親コンポーネントから子コンポーネントに変数を【一つ】渡したいだけの、きわめて単純なソースです。
下記のソースで詳細を示します。
子コンポーネントで定義した変数「text」にて、親コンポーネントで指定した「本日は晴天なり」を表示させるのが目的です。
javascript
1 2/* 親コンポーネント /app/hoge/src/App.vue */ 3 4<template> 5 <Test01 text="本日は晴天なり" /> 6</template> 7 8<script> 9import Test01 from './components/Test01.vue' 10</script> 11//---------- 12 13/* 子コンポーネント /app/hoge/src/components/Test01.vue */ 14<template> 15 <p>{{text}}</p> 16</template> 17 18<script setup> 19defineProps({ 20 text: String 21}) 22</script> 23
発生している問題・分からないこと
今回の問題は、ローカル環境のページを開く、もしくはファイルをセーブした瞬間に、
error 'defineProps' is not defined no-undef
というエラーが発生します。
後述の「試したこと・調べたこと」で見た内容で実際のコードを書き換えました。
node_modules/@vue\vue-loader-v15/.eslintrc.js
ファイルで、ESLintに引っかからないように、コードを追加したのですが、同じエラーが発生します。
【わからないこと】
子コンポーネントの<script setup>
におけるdefineProps
の書き方が悪いのか、もしくはESLintの設定が不正なのかが見当がつかない状態です。
エラーメッセージ
error
1/app/hoge/src/components/Test01.vue 2 XXX:1 error 'defineProps' is not defined no-undef 3 4//上記エラー以外は何も表示されていませんでした。 5 6 7//● yarnのログで出力されたエラー。 8 9 INFO Starting development server... 10 11 ERROR Failed to compile with 1 error 1:21:58 PM 12 13[eslint] 14/app/hoge/src/components/Test01.vue 15 6:1 error 'defineProps' is not defined no-undef 16
該当のソースコード
vue.js
1//【ソース1】 2 3/* 親コンポーネント /app/hoge/src/App.vue */ 4 5<template> 6 <Test01 text="本日は晴天なり" /> 7</template> 8 9<script> 10import Test01 from './components/Test01.vue' 11 12//---------- 13 14/* 子コンポーネント /app/hoge/src/components/Test01.vue */ 15<template> 16 <p>{{text}}</p> 17</template> 18 19<script setup> 20defineProps({ 21 text: String 22}) 23</script> 24 25 26
JavaScript
1//【ソース2】 2/* node_modules/@vue\vue-loader-v15/.eslintrc.js */ 3 4//【修正前】 5module.exports = { 6 root: true, 7 extends: ['plugin:vue-libs/recommended'], 8 rules: { 9 indent: 'off', 10 'space-before-function-paren': 'off' 11 } 12} 13 14//【修正後】 15module.exports = { 16 root: true, 17 extends: ['plugin:vue-libs/recommended'], 18 rules: { 19 indent: 'off', 20 'space-before-function-paren': 'off' 21 }, 22 globals: { 23 "defineProps": "readonly", 24 "defineEmits": "readonly", 25 "defineExpose": "readonly", 26 "withDefaults": "readonly" 27 } 28} 29
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
【参考にしたサイト】
(1)ESLintに'defineProps' is not defined.(no-undef)と言われる
https://commis.hatenablog.com/entry/2021/10/21/113831
(2)'defineProps' is not defined #15015
https://github.com/eslint/eslint/discussions/15015
補足
【Vueのバージョンと、関連ライブラリのバージョン】
shell
1+-- @babel/core@7.27.7 2+-- @babel/eslint-parser@7.27.5 3+-- @vue/cli-plugin-babel@5.0.8 4+-- @vue/cli-plugin-eslint@5.0.8 5+-- @vue/cli-service@5.0.8 6+-- core-js@3.43.0 7+-- eslint-plugin-vue@8.7.1 8+-- eslint@7.32.0 9`-- vue@3.5.17 10
Vueの環境は、Windows11のWSL2-Ubuntu内、Dockerで構築しました。
(参考)Dockerfileの内容
Dockerfile
1 2FROM node:lts-alpine 3 4# vue-cliをインストール 5RUN apk update && \ 6 apk add --no-cache npm && \ 7 npm install --location=global @vue/cli 8 9WORKDIR /app 10
(参考)docker-compose.ymlの内容
yaml
1version: '3' 2 3services: 4 vue-app: 5 build: 6 context: "./" 7 dockerfile: "Dockerfile" 8 ports: 9 - 8080:8080 10 volumes: 11 - ./app:/app 12 tty: true 13 environment: 14 - NODE_ENV=development

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。