esm.sh在Deno deploy下报错

Deno deploy环境下esm.sh会默认把导入的包target设置为deno导致报错"TypeError: Can not modify env vars during execution."
原因可能是默认设置了Process.env.NODE_ENV为production

1 个赞

哪个包?有没有可以复现的 repo?

https://cdn.esm.sh/v64/leancloud-storage@4.12.0/es2021/leancloud-storage.js

https://cdn.esm.sh/v64/leancloud-storage@4.12.0/deno/leancloud-storage.js

最近更新 esm.sh 把 process 的 polyfill 切换到了 deno.land/std/node/process.ts,我修复一下

添加了一个issue:https://github.com/esm-dev/esm.sh/issues/261 ,晚点我更新一下

@so1ve 谢谢反馈,建议遇到问题可以尝试在github上提交issues,这样维护者也能及时收到邮件,也方便问题追踪。

哈哈哈哈好的,主要是不太确定这个是否是一个BUG :joy:

如果添加?target=es2021就可以解决了

在 v65 里修复这个问题了

import AV from "https://esm.sh/leancloud-storage@4.12.0?target=deno&pin=v65";
import * as leanAdapters from "https://esm.sh/@leancloud/platform-adapters-node@1.5.2?target=deno&pin=v65";
AV.setAdapters(leanAdapters);

报错

error: TS2339 [ERROR]: Property 'bind' does not exist on type 'TimerHandler'.
  Property 'bind' does not exist on type 'string'.
      cb.bind(timer)(...args);
         ~~~~
    at https://deno.land/std@0.125.0/node/timers.ts:21:10

TS2339 [ERROR]: Property 'bind' does not exist on type 'TimerHandler'.
  Property 'bind' does not exist on type 'string'.
      cb.bind(timer)(...args);
         ~~~~
    at https://deno.land/std@0.125.0/node/timers.ts:52:10

TS2339 [ERROR]: Property 'randomUUID' does not exist on type 'Crypto'.
const randomUUID = () => crypto.randomUUID();
                                ~~~~~~~~~~
    at https://deno.land/std@0.125.0/node/crypto.ts:11:33

Found 3 errors.

target设置为es2021依然没有这个问题:nauseated_face:会不会是命名冲突

可以试试升级到 Deno 1.18.2,加上 --unstable 参数,process deno ployfill 用了一下不太稳定的api