Punycode在npm中已经被弃用 - 我应该用什么来替代它?

8
我在我的Angular项目中使用npm模块。 VsCode告诉我它已被弃用,https://nodejs.org/api/punycode.html#punycode_punycode进行了确认。
The version of the punycode module bundled in Node.js is being deprecated. In a future major version of Node.js this module will be removed. Users currently depending on the punycode module should switch to using the userland-provided Punycode.js module instead. 

建议切换到“用户提供的”模块。那是什么?
其中有一个链接https://github.com/mathiasbynens/punycode.js,我尝试在我的package.json中包含它而不是“punycode”,但我收到了相同的错误。

你按照自述文件的指示导入了模块吗:const punycode = require('punycode/'); - undefined
我认为这是针对node.js的,因为我们只是在使用es6的import语法,而不是commonJs的node模块。 - undefined
1
只是改变解析的位置而已。你需要强制导入来自本地(node_modules等)而不是从node.js库中导入。例如,尝试使用import punycode from "punycode/"; - undefined
我已经完成了这个任务,并且修改了使用方式,例如将toUnicode更改为punycode.toUnicode(),这样可以“抑制”弃用错误,但是由于没有类型知识(toUnicode是'any'),所以我需要进一步检查并确定。还是谢谢你。 - undefined
1个回答

5
首先:
npm install punycode --save

第二步:
然后在`node_modules`目录中进入tr46 > index.js文件夹。
// Replace this:
const punycode = require('punycode');
// With this:
const punycode = require('punycode/');

1
这是一个变通方法还是建议的做法? - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接