LoginSignup
27
26

More than 1 year has passed since last update.

npm +TypeScript + Nuxt.js で create したらいきなりThis relative module was not found: ./index.vue?vue&type=script&lang=ts& in ./pages/index.vueというエラーが出た

Posted at

よくわからないままですが、一応解決できた?ので記録として残します。

20200811145835.png

結論

  • @nuxt/typescript-runtime と @nuxt/typescript-build の バージョンを固定させた
  • 動くようになったけど、結局よくわからないまま

現象

TypeScriptを有効にして、あとはデフォルトの設定で作成したNuxtプロジェクトで、
今まで出なかった以下のようなエラーが突然出た。

ERROR Failed to compile with 1 errors
This relative module was not found:
./index.vue?vue&type=script&lang=ts& in ./pages/index.vue

実行環境

  • PC: MacBook Pro (Intel Core 2016)
  • OS: macOS Montery12.0.1
  • Node.js v16.9.1
  • Nuxt.js v2.15.8

package.json

{
  "name": "app",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "lint:js": "eslint --ext \".js,.ts,.vue\" --ignore-path .gitignore .",
    "lint:prettier": "prettier --check .",
    "lint": "npm run lint:js && npm run lint:prettier",
    "lintfix": "prettier --write --list-different . && npm run lint:js -- --fix",
    "test": "jest"
  },
  "dependencies": {
    "@nuxtjs/axios": "^5.13.6",
    "core-js": "^3.19.3",
    "nuxt": "^2.15.8",
    "vue": "^2.6.14",
    "vue-server-renderer": "^2.6.14",
    "vue-template-compiler": "^2.6.14",
    "webpack": "^4.46.0"
  },
  "devDependencies": {
    "@babel/eslint-parser": "^7.16.3",
    "@nuxt/types": "^2.15.8",
    "@nuxt/typescript-build": "^2.1.0",
    "@nuxtjs/eslint-config-typescript": "^8.0.0",
    "@nuxtjs/eslint-module": "^3.0.2",
    "@vue/test-utils": "^1.3.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "^27.4.4",
    "eslint": "^8.4.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-nuxt": "^3.1.0",
    "eslint-plugin-vue": "^8.2.0",
    "jest": "^27.4.4",
    "prettier": "^2.5.1",
    "ts-jest": "^27.1.1",
    "vue-jest": "^3.0.4"
  }
}

issue を発見したが

調べてみると以下の issue を発見した。

ただ、こちらの issue は2020年9月3日に上がって、
現在は対応済みということで Closed になっている。

この記事を投稿しているのは、2021年12月26日なので、
かなり前の issue である。

上記の issue をざっくりと申し上げると、
@nuxt/typescript-runtime と @nuxt/typescript-build のバージョンが原因だったと書かれていました。

一応、修正プルリクは以下です。

やってみたこと

とりあえず、動かないので以下のことをやってみました。

  • node_modules の再インストール
% rm -rf node_modules
% npm i
% npm run dev

だめでした。

次に以下のことをやりました。

  • issue に書かれているバージョンに固定
  • ついでに、@nuxt/typescript-runtime も入れておく
% npm i -D @nuxt/typescript-runtime@2.0.0
% npm i -D @nuxt/typescript-build@2.0.0
% rm -rf node_modules
% npm i
% npm run dev

動きました。。。

Nuxt.js の同じバージョンで何度もプロジェクトを作っていましたが、
今までこんなことはありませんでした。

すでに issue の方で対応済みのはずなのに、結局よくわからないまま。。

27
26
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
26