VueJS和Vite:意外字符“�”(请注意,您需要插件来导入非JavaScript的文件)

okxuctiv  于 2023-11-21  发布在  Vue.js
关注(0)|答案(1)|浏览(218)

我试图理解为什么我在VueJS Web应用程序上得到错误:[commonjs--resolver] Unexpected character '�' (Note that you need plugins to import files that are not JavaScript) file: /..../..../WebProjects/..../ProjectName/node_modules/fsevents/fsevents.js:1:0。这个错误让我认为vite不知何故无法构建在node_modules目录下fsevents文件夹中的fsevents.node文件。
我也不确定fsevents包是如何安装的;我没有显式安装它。我想运行npm explain fsevents可能会揭示我安装的哪些包依赖于fsevents
我的package.json应用程序并不太复杂:

{
  "name": "project-name",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "dev": "vite",
    "build": "run-p type-check build-only",
    "preview": "vite preview",
    "build-only": "vite build",
    "type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false",
    "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
    "format": "prettier --write src/"
  },
  "dependencies": {
    "@vitejs/plugin-basic-ssl": "^1.0.1",
    "axios": "^1.5.1",
    "bulma": "^0.9.4",
    "chart.js": "^4.4.0",
    "is-what": "^4.1.15",
    "pinia": "^2.1.6",
    "rollup": "^4.3.0",
    "vite-plugin-vuetify": "^1.0.2",
    "vue": "^3.3.4",
    "vue-chartjs": "^5.2.0",
    "vue-loading-overlay": "^6.0.3",
    "vue-router": "^4.2.4",
    "vue3-easy-data-table": "^1.5.47",
    "vuetify": "^3.3.23"
  },
  "devDependencies": {
    "@rushstack/eslint-patch": "^1.3.2",
    "@tsconfig/node18": "^18.2.0",
    "@types/node": "^18.18.5",
    "@vitejs/plugin-vue": "^4.4.0",
    "@vitejs/plugin-vue-jsx": "^3.0.2",
    "@vue/eslint-config-prettier": "^8.0.0",
    "@vue/eslint-config-typescript": "^11.0.3",
    "@vue/tsconfig": "^0.4.0",
    "eslint": "^8.46.0",
    "eslint-plugin-vue": "^9.16.1",
    "npm-run-all": "^4.1.5",
    "prettier": "^3.0.0",
    "sass": "^1.69.3",
    "sass-loader": "^13.3.2",
    "typescript": "~5.1.6",
    "vite": "4.5.0",
    "vite-plugin-native": "^0.2.0",
    "vue-tsc": "^1.8.8"
  }
}

字符串
不知道这里发生了什么,还有什么我可以尝试。

v9tzhpje

v9tzhpje1#

在查看了我的代码库之后,发现我的一个类型脚本文件中有一个未使用的导入导致了这个问题:

import vue from "@vitejs/plugin-vue";

字符串
我删除了这个未使用的导入,我的项目能够成功构建!

相关问题