malibil
malibil

Reputation: 179

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"

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

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

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"
}

}

Upvotes: 1

Views: 9339

Answers (1)

malibil
malibil

Reputation: 179

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

"type": "module"

Upvotes: 4

Related Questions