GreatAuk / plugin-web-update-notification

Detect webpage updates and notify user to reload. support Vite, Umijs, and Webpack.
MIT License
490 stars 42 forks source link

ReferenceError: __dirname is not defined #21

Closed pmiguelmartins closed 1 year ago

pmiguelmartins commented 1 year ago

In Vite Vue 3 width typescript

I'm receiving this error

I try to use injectFileBase but when I'm building always receive this error

How can I solve

Thansk

GreatAuk commented 1 year ago

provide vite and node version

GreatAuk commented 1 year ago

After version 1.2.0, in most case, you not need to set injectFileBase, it will be automatically detected from the base of vite config、publicPath of webpack config or publicPath of umi config

vaynevayne commented 1 year ago

import { webUpdateNotice } from '@plugin-web-update-notification/vite' 依然不行啊 ^1.5.2

image

没找到你的源码, 不知道在哪里改, 假如使用 es module (export import )写的nodejs 项目, 你要自己声明__dirname

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

const __dirname = dirname(fileURLToPath(import.meta.url));

// or

// expose.js
module.exports = {__dirname};

// use.mjs
import expose from './expose.js';
const {__dirname} = expose;

https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules

GreatAuk commented 1 year ago

晚上我修下。你本地 node 版本多少,改完我测试下。

vaynevayne commented 1 year ago

v16.16.0

GreatAuk commented 1 year ago

其实我是有处理 __dirname 的,只是打包时,target 设置错了。

export function get__Dirname() {
  if (import.meta?.url)
    return dirname(fileURLToPath(import.meta.url))
  return __dirname
}

可以安装下最新版本的试试 https://github.com/GreatAuk/plugin-web-update-notification/commit/74466bf88db9bea6ec5c44afd040f3f98be3d2de

GreatAuk commented 1 year ago

@pmiguelmartins sorry, I don't notice that you are a English user, this issue fixed in 1.5.3.

pmiguelmartins commented 1 year ago

@pmiguelmartins sorry, I don't notice that you are a English user, this issue fixed in 1.5.3.

Already try and work just fine

thanks