node.js - as-pect.config.js 被视为 ES 模块文件,因为它是一个 .js 文件,其最近的父 package.json 包含 "type": "module"

当我使用方面进行测试时,我在带有 NEAR 的 CRUD dApp 中遇到错误。我得到的整个错误如下;

yarn test

[错误] 加载 [/Users/malibilgin/Documents/Web3/order-management-with-near/contract/as-pect.config.js] 时出现问题。错误 [ERR_REQUIRE_ESM]: 来自 /Users/malibilgin/Documents/Web3/order 的 ES 模块 /Users/malibilgin/Documents/Web3/order-management-with-near/contract/as-pect.config.js 的 require() -management-with-near/contract/node_modules/asbuild/node_modules/@as-pect/cli/lib/run.js 不支持。 as-pect.config.js 被视为 ES 模块文件,因为它是一个 .js 文件,其最近的父 package.json 包含“type”:“module”,它将该包范围内的所有 .js 文件声明为 ES 模块。而是将 as-pect.config.js 重命名为以 .cjs 结尾,将要求代码更改为使用所有 CommonJS 模块中可用的动态 import(),或将“type”:“module”更改为“type”:“commonjs”在 /Users/malibilgin/Documents/Web3/order-management-with-near/contract/package.json 中将所有 .js 文件视为 CommonJS(对所有 ES 模块使用 .mjs)。在运行 (/Users/malibilgin/Documents/Web3/order-management-with-near/contract/node_modules/asbuild/node_modules/@as-pect/cli/lib/run.js:182:25) 在对象。 asp (/Users/malibilgin/Documents/Web3/order-management-with-near/contract/node_modules/asbuild/node_modules/@as-pect/cli/lib/index.js:64:9) 在对象。 (/Users/malibilgin/Documents/Web3/order-management-with-near/contract/node_modules/asbuild/node_modules/@as-pect/cli/lib/test.js:2:28){ 代码:'ERR_REQUIRE_ESM ' } error 命令失败,退出代码为 1。

但是当我从地址克隆时

https://github.com/near-examples/crud-tutorial.git

并对其进行测试,此处找到的测试成功。我不明白我在哪里错过了它。我做的项目类似于这个克隆。

我的包.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"
}

}

回答1

在挣扎了 1 天并在这里提出我的问题后,我能够在大约 10 分钟后解决我的问题。我所要做的就是在我的 package.json 中删除它

"type": "module"

相似文章

随机推荐

最新文章