简体   繁体   English

Nanoid 库不能用作事物板资源

[英]Nanoid library not working as a thingsboard resource

I need to generate a 10 character id for a project in Thingsboard, i'm facing a problem with the nanoid lib.我需要为 Thingsboard 中的一个项目生成一个 10 个字符的 ID,我遇到了 nanoid 库的问题。 I need to use the cdnjs so i've tried first with the 4.0 version (the index.browser.min.js one) and it's giving me this problem as soon as i click on execute.我需要使用 cdnjs,所以我首先尝试了 4.0 版本(index.browser.min.js 版本),一旦我点击执行,它就会给我这个问题。 "Unexpexted token export" error . “意外令牌导出”错误

So i tried with the 3.3.4 version Cannot use import statement outside a module .所以我尝试了 3.3.4 版本, Cannot use import statement outside a module

Thingsboard lets you program in javscript and gives you a space for cdnjs to import library/resources Thingsboard . Thingsboard 允许您在 javscript 中编程,并为您提供 cdnjs 导入库/资源Thingsboard的空间。

I'm in a clean widget creation so i don't think something is interfering, i've tried with other lib (like uuid) and it works just fine.我正在创建一个干净的小部件,所以我不认为有什么干扰,我尝试过使用其他库(如 uuid),它工作得很好。 I've even tried with the html but the outcome it's the same.我什至尝试过使用 html,但结果是一样的。

Does somebody knows why it's doing like this and how to fix it?有人知道为什么会这样以及如何解决吗?

self.onInit = function() {
    import('https://cdn.jsdelivr.net/npm/nanoid/nanoid.js').then(
        nanoid => {
            console.log(nanoid.nanoid());
        }
    );

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM