Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Javascript Chaincode cannot install due to error Cannot find module 'moment' #76

Open
riki95 opened this issue Apr 20, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@riki95
Copy link

riki95 commented Apr 20, 2023

I am using this VSCode extension frequently to debug chaincodes written in Typescript.
Now I want to test it on my chaincode written in Javascript and this does not work.

I am correctly running my blockchain env with Docker Desktop on my Mac and I have my smart contracts on a folder.
For Typescript, I have my launch.json file written like this:

launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "hlf-node",
            "request": "launch",
            "name": "Debug Smart Contract"
        }
    ]
}

When I press "Debug chaincode" on VS Code, it deploys the chaincode and, once up and running, I launch tests with the test.fabric file, using a syntax like:

{
        "invoke": "ClassTokenContract:create",
        "args": ["{\"id\":\"1\"}"]
    },

Everything works, but if I do the same thing with a Javascript file, I get this error:

Error
Error: Cannot find module 'moment'
Require stack:
- /GitHub/dc/dc-chaincode/dgc/utils/Utils.js
- /GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/classToken.js
- /GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/erc-list-contract.js
- /GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/class-token-contract.js
- /GitHub/dc/dc-chaincode/dgc/ERC-1203/index.js
- /GitHub/dc/dc-chaincode/dgc/ERC-1203/node_modules/fabric-shim/lib/contract-spi/bootstrap.js
- /GitHub/dc/dc-chaincode/dgc/ERC-1203/node_modules/fabric-shim/lib/cmds/metadata/lib/generate.js
- /GitHub/dc/dc-chaincode/dgc/ERC-1203/node_modules/fabric-shim/lib/cmds/metadata.js
- /GitHub/dc/dc-chaincode/dgc/ERC-1203/node_modules/yargs/index.js
- /GitHub/dc/dc-chaincode/dgc/ERC-1203/node_modules/fabric-shim/cli.js
    at Function.Module._resolveFilename (/GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/internal/modules/cjs/loader.js:933:15)
    at Function.Module._load (/GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/internal/modules/cjs/loader.js:778:27)
    at Module.require (/GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/internal/modules/cjs/loader.js:1005:19)
    at require (/GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/internal/modules/cjs/helpers.js:102:18)
    at Object.<anonymous> (/GitHub/dc/dc-chaincode/dgc/utils/Utils.js:3:16)
    at Module._compile (/GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/internal/modules/cjs/loader.js:1105:14)
    at Object.Module._extensions..js (/GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/internal/modules/cjs/loader.js:1159:10)
    at Module.load (/GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/internal/modules/cjs/loader.js:981:32)
    at Function.Module._load (/GitHub/dc/dc-chaincode/dgc/ERC-1203/lib/internal/modules/cjs/loader.js:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {code: 'MODULE_NOT_FOUND', requireStack: Array(10), stack: 'Error: Cannot find module 'moment'
Require st…re (node:internal/modules/cjs/loader:1005:19)', message: 'Cannot find module 'moment'
Require stack:
-…any/ERC-1203/node_modules/fabric-shim/cli.js'}

This is happening only running my contract in local, because on other env and clusters it is working perfectly.
Moment is a package inserted in package.json and used insile a Javascript file which is symlinked into the smart contract folder.
I always used symlinks, also for typescript contracts, and they always worked correctly.

@riki95 riki95 added the bug Something isn't working label Apr 20, 2023
@ashwath-spdr
Copy link
Contributor

@riki95, looks like we missed this issue earlier and came across this while cleaning up the bugs. Please let us know if you are still facing similar issue with the latest version of the extension.

Regarding the issue, not sure if its because of symlinked file. Pls see if adding "--preserve-symlinks" in the launch.json file helps as mentioned here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@riki95 @ashwath-spdr and others