Node.js Import Error after“type”:“module”[已关闭]

ncgqoxb0  于 2023-08-04  发布在  Node.js
关注(0)|答案(1)|浏览(108)

**已关闭。**此问题需要debugging details。它目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答这个问题。
4天前关闭。
Improve this question
当我试图从controller/auth.js导入register函数时,我得到了这个错误:
node:internal/errors:477 ErrorCaptureStackTrace(err);^错误[ERR_MODULE_NOT_FOUND]:找不到模块
这是package.json

{
  "dependencies": {
    "bcrypt": "^5.1.0",
    "body-parser": "^1.20.2",
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "helmet": "^6.0.1",
    "jsonwebtoken": "^9.0.0",
    "mongoose": "^7.0.1",
    "morgan": "^1.10.0"
  },
  "name": "server",
  "version": "1.0.0",
  "main": "index.js",
  "type": "module",
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon --experimental-modules index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": ""
}

字符串
x1c 0d1x的数据
我找到了一些soultions,但它们最终没有像adding .js那样工作。
我想解决的错误和进口注册功能,谢谢提前;)

yfjy0ee7

yfjy0ee71#

//️导入错误

import { sum } from '.another-file.js';

字符串
//正确导入

import { sum } from './another-file.js';


来源:https://bobbyhadz.com/blog/javascript-error-err-module-not-found-cannot-find-module#:~:text= The%20%22Error%20%5BERR_MODULE_NOT_FOUND%5D%3A,extension%20when%20importing%20local%20files.

相关问题