AS-PECT.CONFIG.JS被视为ES模块文件,因为它是一个.js文件,其最接近的父套件包含“类型”:“ type”:; quot'module;
当我用来测试时,我会在Crud Dapp中出现错误。我得到的整个错误如下;
yarn test
[错误]存在问题加载问题[/USERS/MALIBILGIN/DOCUMENTS/WEB3/WEER-MANAGHAIGH-WITH-NEAR/CONTRACT/AS-PECT.CONFIG.JS]。 错误[ERR_REQUIRE_ESM]:ES模块/user/malibilgin/documents/web3/erorder-management-with-near/contract/as-preck.config.js的ES oprec() -with-near/contract/node_modules/asbuild/node_modules/@as-prece/cli/lib/run.js不支持。 AS-PECT.CONFIG.JS被视为ES模块文件,因为它是一个.js文件,其最近的父套件包含“ type”:“模块”:“模块”,该文件在该软件包范围中声明所有.js文件为ES模块。 而是重命名为.cjs结束的AS-PECT.CONFIG.JS,更改使用DynamiC Import()的代码,该代码在所有CommonJs模块中可用,或更改“ type”:“ type”:“模块”为“类型”:“ commonjs”:“ commonjs”:“ commonj”:“在/users/malibilgin/documents/web3/order-management-with-near/contract/package.json中,将所有.js文件视为commonjs(而是将.mjs用于所有ES模块)。 在Run(/Users/malibilgin/documents/web3/orore-management-with-near/contract/node_modules/asbuild/node_modules/@as-prece/cli/cli/lib/lib/run.js:182:25) 在Object.asp(/USERS/Malibilgin/documents/web3/web3/eroragement-with-near/contract/node_modules/asbuild/node_modules/@as-precp/cli/lib/lib/index.js.js:64:9) 在对象。 (/users/malibilgin/documents/web3/order-management-with-near/contract/node_modules/asbuild/node_modules/@as-pect/cli/lib/lib/test.js:2:28){ 代码:'err_require_esm' } 出口代码1。
失败命令失败
但是当我从地址克隆时
https://github.com/near-examples/near-examples/crud-tutorial.git.git.git
测试它,这里发现的测试成功。我不明白我错过了它。我制作的项目类似于这个克隆。
我的包裹。
{
"name": "contract",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "module",
"exports": {
".": {
"import": "./build/release.js",
"types": "./build/release.d.ts"
}
},
"scripts": {
"asbuild:debug": "asc assembly/index.ts --target debug",
"asbuild:release": "asc assembly/index.ts --target release",
"start": "npx serve .",
"build": "asb",
"deploy": "near dev-deploy build/release/contract.wasm",
"dev": "npm run build && npm run deploy",
"test": "asp",
"asbuild:untouched": "asc assembly/index.ts --target debug",
"asbuild:optimized": "asc assembly/index.ts --target release",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized"
},
"devDependencies": {
"assemblyscript": "^0.19.14"
},
"dependencies": {
"@assemblyscript/loader": "^0.19.14",
"asbuild": "^0.2.0",
"assemblyscript": "^0.19.14",
"near-cli": "^3.3.0",
"near-sdk-as": "^3.2.3"
}
}
When I test with as-pect I get an error in CRUD dApp with NEAR. The whole error I get is as follows;
yarn test
[Error] There was a problem loading [/Users/malibilgin/Documents/Web3/order-management-with-near/contract/as-pect.config.js].
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/malibilgin/Documents/Web3/order-management-with-near/contract/as-pect.config.js from /Users/malibilgin/Documents/Web3/order-management-with-near/contract/node_modules/asbuild/node_modules/@as-pect/cli/lib/run.js not supported.
as-pect.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename as-pect.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/malibilgin/Documents/Web3/order-management-with-near/contract/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at run (/Users/malibilgin/Documents/Web3/order-management-with-near/contract/node_modules/asbuild/node_modules/@as-pect/cli/lib/run.js:182:25)
at Object.asp (/Users/malibilgin/Documents/Web3/order-management-with-near/contract/node_modules/asbuild/node_modules/@as-pect/cli/lib/index.js:64:9)
at Object. (/Users/malibilgin/Documents/Web3/order-management-with-near/contract/node_modules/asbuild/node_modules/@as-pect/cli/lib/test.js:2:28) {
code: 'ERR_REQUIRE_ESM'
}
error Command failed with exit code 1.
but when I clone from the address
and test it, the test found here works successfully. I couldn't understand where I missed it. The project I made is similar to this clone.
my package.json;
{
"name": "contract",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "module",
"exports": {
".": {
"import": "./build/release.js",
"types": "./build/release.d.ts"
}
},
"scripts": {
"asbuild:debug": "asc assembly/index.ts --target debug",
"asbuild:release": "asc assembly/index.ts --target release",
"start": "npx serve .",
"build": "asb",
"deploy": "near dev-deploy build/release/contract.wasm",
"dev": "npm run build && npm run deploy",
"test": "asp",
"asbuild:untouched": "asc assembly/index.ts --target debug",
"asbuild:optimized": "asc assembly/index.ts --target release",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized"
},
"devDependencies": {
"assemblyscript": "^0.19.14"
},
"dependencies": {
"@assemblyscript/loader": "^0.19.14",
"asbuild": "^0.2.0",
"assemblyscript": "^0.19.14",
"near-cli": "^3.3.0",
"near-sdk-as": "^3.2.3"
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在挣扎了1天并在这里问我的问题之后,大约10分钟后,我能够解决我的问题。我要做的就是在我的包装中删除此功能。
After struggling for 1 day and asking my question here, I was able to solve my problem about 10 minutes later. all I had to do was delete this in my package.json