小编KAM*_*KAM的帖子

使用“路径”中的导入路径时无法读取未定义的属性“解析”

使用时:

import path from 'path';

path.resolve('/')
Run Code Online (Sandbox Code Playgroud)

我收到标题错误,但是当我使用

require('path').resolve('messages.json'))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

import { readFile, writeFile } from 'fs/promises';
import { v4 as uuidv4 } from 'uuid';
import path from 'path';

interface MessagesJson {
  messages: Array<{ content: string; id: string }>;
}

export class MessagesRepository {
  async findOne(id: string): Promise<string> {
    return id;
  }

  async findAll(): Promise<any> {
    return null;
  }

  async create(message: any): Promise<any> {
    console.log(' dirname', require('path').resolve('messages.json'));
    console.log(' path.resolve', path.resolve('/'));
    // console.log(' path.resolve', path.resolve(__dirname, '/src'));
    const messages: any = await readFile('src/messages.json', 'utf-8'); …
Run Code Online (Sandbox Code Playgroud)

node.js typescript nestjs

6
推荐指数
1
解决办法
4442
查看次数

标签 统计

nestjs ×1

node.js ×1

typescript ×1