質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

2回答

7157閲覧

npm run buildができない

jomaboy

総合スコア4

Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/10/20 08:10

前提・実現したいこと

プログラミング初心者です。うまく質問できないですがよろしくお願いします。
vue.jsのnpm run buildをしたいです。
エラー内容のTo install it, you can run: npm install --save @/pages/HomePageを試したのですが、またエラーが出てつまずいています。vscodeのデバックを使ったらSyntaxError: Unexpected identifierがでましたが、どこが原因かわからない状況です。教えていただきたいです。

発生している問題・エラーメッセージ

(base) MacBook-Air:frontend imaijoma$ npm run build > frontend@0.1.0 build /Users/imaijoma/drf-vue-sample/frontend > vue-cli-service build ⠸ Building for production... ERROR Failed to compile with 1 errors 16:34:31 This dependency was not found: * @/pages/HomePage in ./src/router.js To install it, you can run: npm install --save @/pages/HomePage ERROR Build failed with errors. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! frontend@0.1.0 build: `vue-cli-service build` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the frontend@0.1.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /Users/imaijoma/.npm/_logs/2019-10-20T07_34_31_801Z-debug.log
(base) MacBook-Air:frontend imaijoma$ npm install --save @/pages/HomePage npm ERR! code ENOLOCAL npm ERR! Could not install from "@/pages/HomePage" as it does not contain a package.json file. npm ERR! A complete log of this run can be found in: npm ERR! /Users/imaijoma/.npm/_logs/2019-10-20T07_33_53_671Z-debug.log
/usr/local/bin/node --inspect-brk=9507 frontend/src/router.js Debugger listening on ws://127.0.0.1:9507/588806de-5fda-4bd5-8a18-4c4f3d28c985 For help, see: https://nodejs.org/en/docs/inspector Debugger attached. Waiting for the debugger to disconnect... /Users/imaijoma/drf-vue-sample/frontend/src/router.js:1 import Vue from 'vue' ^^^ SyntaxError: Unexpected identifier at Module._compile (internal/modules/cjs/loader.js:872:18) at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10) at Module.load (internal/modules/cjs/loader.js:790:32) at Function.Module._load (internal/modules/cjs/loader.js:703:12) at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)

該当のソースコード

vue.js

1import Vue from 'vue' 2import VueRouter from 'vue-router' 3import HomePage from '@/pages/HomePage' 4 5Vue.use(VueRouter) 6 7const router = new VueRouter({ 8 mode: 'history', 9 routes: [ 10 { path: '/', component: HomePage }, 11 { path: '*', redirect: '/' } 12 ] 13}) 14 15

試したこと

ここに問題に対して試したことを記載してください。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

router オブジェクトを作ってインポートするだけでは不十分で、Vueのコンポーネントへ渡す必要があります。

src/index.js の中で

js

1import router from./router’ 2 3new Vue({ 4 router, /* 直接渡す */ 5 /* dataなどの他の値 */ 6})

のように 直接渡してあげる必要があります。

https://router.vuejs.org/ja/guide/#javascript

投稿2019/11/05 00:48

kaorun343

総合スコア47

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

■ 追記
コメント欄でソースの全文について聞いて、下記の対応を提示。 エラーは回避できたとのこと。

router.js の最後に追加

js

1export default router

main.js の import store from './store' の次の行に追加

js

1import './router'




■ 最初の回答

src/pages/HomePage.vue というファイルがあるとして、、
拡張子を指定していないからでは?

js

1import HomePage from '@/pages/HomePage'

js

1import HomePage from '@/pages/HomePage.vue'

投稿2019/10/20 10:31

編集2019/10/20 13:21
tanishi_a

総合スコア484

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

jomaboy

2019/10/20 11:35

回答ありがとうございます。 指定してみたのですが、変わらずです、、
tanishi_a

2019/10/20 11:36

src/pages/HomePage.vue は存在するのですか?
jomaboy

2019/10/20 11:40

はい、存在します!
tanishi_a

2019/10/20 11:45 編集

vue が入っていなかったり・・? npm install vue (すみませんこれ 回答じゃなくて質問の欄でやるべきでしたね・・)
jomaboy

2019/10/20 11:50

インストールしてみましたが、、、 ``` (base) MacBook-Air:frontend imaijoma$ npm install vue npm WARN bootstrap@4.3.1 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself. + vue@2.6.10 updated 1 package and audited 24240 packages in 12.059s found 0 vulnerabilities (base) MacBook-Air:frontend imaijoma$ npm install --save @/pages/HomePage npm ERR! code ENOLOCAL npm ERR! Could not install from "@/pages/HomePage" as it does not contain a package.json file. npm ERR! A complete log of this run can be found in: npm ERR! /Users/imaijoma/.npm/_logs/2019-10-20T11_46_12_563Z-debug.log ```
tanishi_a

2019/10/20 11:58

全部のソースを載せることは可能ですか?
jomaboy

2019/10/20 12:16

お願いします!
tanishi_a

2019/10/20 12:26 編集

main.js の 9行目あたりに 下記を足したら、npm run build 自体は出来るようには なりましたが。 import './router'
jomaboy

2019/10/20 12:38 編集

import './router'いれたらこうなりました???? (base) MacBook-Air:frontend imaijoma$ npm run build > frontend@0.1.0 build /Users/imaijoma/drf-vue-sample/frontend > vue-cli-service build ⠸ Building for production... ERROR Failed to compile with 1 errors 21:34:01 error in ./src/router.js Module Error (from ./node_modules/thread-loader/dist/cjs.js): /Users/imaijoma/drf-vue-sample/frontend/src/router.js 7:7 error 'router' is assigned a value but never used no-unused-vars ✖ 1 problem (1 error, 0 warnings) @ ./src/main.js 7:0-30 11:0-18 18:10-16 @ multi ./src/main.js ERROR Build failed with errors. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! frontend@0.1.0 build: `vue-cli-service build` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the frontend@0.1.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /Users/imaijoma/.npm/_logs/2019-10-20T12_34_02_086Z-debug.log
tanishi_a

2019/10/20 12:42

そしたら、手元のソースと 上げてもらったソースは違うものだと思います。 比較してみてください。
jomaboy

2019/10/20 12:57

確認しましたが一緒です????
tanishi_a

2019/10/20 12:59

router.js の最後に export default router main.js の import store from './store' の次の行に import './router' ではどうでしょう。
jomaboy

2019/10/20 13:10

できましたーーーー!???? 何日もできず、辛かったので夜遅いのに本当にありがとうございました。 なぜ直ったのかの理解は微妙ですが、とりあえず先に進められそうです
tanishi_a

2019/10/20 13:14

進んだようで良かったです。 一応補足すると、 ・ main.js の下の方で router を import していないのに使っていたので、import した ・ router.js は、export default で、import した先のファイルで読めるようにしてる です。
jomaboy

2019/10/20 13:25

もともとmain.jsにimport router from './router'を書いているのですがこれではrouterをimportできていないのでしょうか?
tanishi_a

2019/11/05 09:47 編集

すみません。返信を見落としてました。 import するには export もセットで必要、というような理解です。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問