直接把代码放到根本录会报错,有官方的大大出来指导一下吗
这就沉了吗
谢谢大佬!!!
还是不行啊,报错
[Scene] 无法从 pack:///mods/file/C:/Users/admin/AStarPathSearching/node_modules/express/lib/express.js 解析出模块 events。
express ?怎么会引入这个模块,这是nodejs express框架里面的吧。肯定也不是所有npm模块都能在creator里面使用吧,这个一般也要是浏览器支持的模块才行吧。你不会还想在浏览器上搭建web服务器吧。。。
我引入 request 也不行啊
Unable to resolve bare specifier ‘crypto’ from http://localhost:7457/scripting/x/mods/file/C:/Users/Administrator/NPM/node_modules/request/lib/helpers.js (SystemJS Error#8 https://git.io/JvFET#8)
at throwUnresolved (system.js:696)
at SystemJS.systemJSPrototype.resolve (system.js:692)
at SystemJS.systemJSPrototype.resolve (system.js:1048)
at system.js:335
at Array.map ()
at system.js:333
at
肯定不行啊
你想要GET ,POST 可以使用 XMLHttpRequest
官方示例里面的 ```
protobufjs
有没有解决?遇到同样的问题
没有,问问楼上的大神
protobufjs这个模块能引入,其他的我就不知道了
感觉不像是我们使用的错。
index.js:1 Error: Unable to resolve bare specifier ‘crypto’ from http://localhost:7456/scripting/x/mods/file/C:/xxx/node_modules/sjcl/sjcl.js (SystemJS Error#8 https://git.io/JvFET#8)
at throwUnresolved (resolve.js:12)
at SystemJS.systemJSPrototype.resolve (resolve.js:8)
at SystemJS.systemJSPrototype.resolve (named-register.js:45)
at system-core.js:145
at Array.map ()
at system-core.js:143
大神的意思是,不是所有的模块都能用
大家有导入成功么, 我导入axios, npm, github的, esm的版本都试了, 还是不行, 文档写的什么.cjs,.mjs也试了也没成功~~~
看看它有没有web版本
自己写了~ 也很方便~~
import { $g } from "../../frame/speed.do";
/*
* @Author: gagahappy<15020055@qq.com>
* @Date: 2021-08-07 15:22:59
* @LastEditors: gagahappy<15020055@qq.com>
* @LastEditTime: 2021-08-07 16:42:37
* @Description:
*/
export class NetHttp {
/** 在每个发出的URL前添加的路径 */
public static apiURL: string = ''
public static post(url: string, data: any): Promise<string> {
return new Promise((resolve, reject) => {
const xhr: XMLHttpRequest = new XMLHttpRequest()
const params: URLSearchParams = new URLSearchParams()
const dataSource: any = new Object()
dataSource.sourceURL = url;
(xhr as any).dataSource = dataSource
for (const key in data) {
if ($g.hasKey(data, key)) {
dataSource[key] = data[key]
params.append(key, data[key])
}
}
xhr.onreadystatechange = function () {
// $g.log(`[NET ←] readyState : ${xhr.readyState} status:${xhr.status} `, this)
switch (xhr.readyState) {
case 0:// 对象创建,未调用 open()
// $g.log('[NET ←]XMLHttpRequest 未初始化')
break
case 1:// 调用open(),未调用 send()
// $g.log('[NET ←]XMLHttpRequest 载入')
break
case 2:// 请求已经发送完成
// $g.log('[NET ←]XMLHttpRequest 载入完成')
break;
case 3: // 已经接收部分数据。但若在此时调用responseBody和responseText属性获取部分结果将会产生错误,因为状态和响应头部还不完全可用
// $g.log('[NET ←]XMLHttpRequest 交互')
break;
case 4:// 已经接收到了全部数据,并且连接已经关闭。
// 响应中的数字状态码:表示为有效响应,成功的请求
$g.log(`[NET ←] readyState : ${xhr.readyState} status:${xhr.status} `, this)
if (xhr.status >= 200 && xhr.status < 400) {
const res: string = xhr.responseText
if (res) {
// 解析完的json 文件再返回 回调函数
return resolve(JSON.parse(res))
} else {
$g.log('[NET ←]返回字符串为空', this);
return resolve('')
}
}
break;
}
}
xhr.onerror = function (this: XMLHttpRequest, e: ProgressEvent<EventTarget>) {
$g.log('[NET ← ] OnError', e)
return resolve('')
}
xhr.ontimeout = function (this: XMLHttpRequest, e: ProgressEvent<EventTarget>) {
$g.log('[NET ← ] OnTimeOut', e)
return resolve('')
}
xhr.open("POST", `${NetHttp.apiURL}${url}`, true);
// note: In Internet Explorer, the timeout property may be set only after calling the open()
// method and before calling the send() method.
// 超时时间(毫秒)
xhr.timeout = 5000
// 告诉服务器如何解析内容
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')
xhr.setRequestHeader('Access-Control-Allow-Origin', '*')
$g.log('[NET → ]', xhr)
xhr.send(params);
})
}
}
这是啥,你手写了一个axio?
node-rsa
Preview]Error: Unable to resolve bare specifier ‘constants’ from http://localhost:7456/scripting/x/mods/fs/0/node_modules/node-rsa/src/NodeRSA.js (SystemJS Error#8 https://git.io/JvFET#8)
at throwUnresolved (http://localhost:7456/scripting/systemjs/system.js:696:11)
at SystemJS.systemJSPrototype.resolve (http://localhost:7456/scripting/systemjs/system.js:692:102)
这个怎么解决呢