klren0312 / daliy_knowledge

知识积累,正确使用方式是watch
21 stars 4 forks source link

nodejs "type": "module"时 报错ReferenceError: __dirname is not defined #843

Open klren0312 opened 2 months ago

klren0312 commented 2 months ago

解决方法

import path from 'path'
import { fileURLToPath } from 'url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
console.log(path.join(__dirname, '/uploads'))