Javascript 使用UUID时使用typescript中断生成的库
所以我遇到了这个问题,我使用typescript和axios构建了一个同构库,它工作得很好 它在其他项目中编译、发布和安装/导入,没有任何问题。我可以在Node.js和浏览器中使用它 安装程序包UUID:Javascript 使用UUID时使用typescript中断生成的库,javascript,node.js,typescript,Javascript,Node.js,Typescript,所以我遇到了这个问题,我使用typescript和axios构建了一个同构库,它工作得很好 它在其他项目中编译、发布和安装/导入,没有任何问题。我可以在Node.js和浏览器中使用它 安装程序包UUID:npm install UUID后,导入我的库的所有项目都开始失败,我开始在浏览器中遇到此错误: external "crypto":1 Uncaught ReferenceError: require is not defined at Object.crypto
npm install UUID
后,导入我的库的所有项目都开始失败,我开始在浏览器中遇到此错误:
external "crypto":1 Uncaught ReferenceError: require is not defined
at Object.crypto (external "crypto":1)
at __webpack_require__ (bootstrap:19)
at Module.../api-manager/node_modules/@lukeed/uuid/dist/index.mjs (index.mjs:1)
at __webpack_require__ (bootstrap:19)
at Object.../my-library/lib/MyLibrary.js (MyLibrary.js:20)
at __webpack_require__ (bootstrap:19)
at Object.../api-manager/lib/index.js (index.js:13)
at __webpack_require__ (bootstrap:19)
at Object../src/client/pages/LoginPage/index.tsx (index.tsx:34)
at __webpack_require__ (bootstrap:19)
在生成客户端项目时,控制台中会显示以下错误消息:
ERROR in ../my-library/node_modules/@lukeed/uuid/dist/index.mjs 11:11-22
Can't import the named export 'randomBytes' from non EcmaScript module (only default export is available)
@ ../my-library/lib/MyLibrart.js
@ ../my-library/lib/index.js
@ ./src/client/client.tsx
当我检查我的库
的编译代码时,我得到以下结果:
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiManager = void 0;
var axios_1 = __importDefault(require("axios")); // This has always worked!
// import { v4 as uuidv4 } from 'uuid'; // Tried this library and still failing
var uuid_1 = __importDefault(require("@lukeed/uuid")); // This is not working
var API_ID = "my-library-";
var MyLibrary = /** @class */ (function () {
function MyLibrary(config) {
...
“严格使用”;
var uu assign=(this&&this.u assign)| |函数(){
__赋值=对象。赋值| |函数(t){
for(var s,i=1,n=arguments.length;i
老实说,这里没有多少线索。非常感谢您的帮助您可以发布您的tsconfig以及如何导入
uuid
库吗?