Developer forum

Forum » Dynamicweb 10 » CLI throwing error message

CLI throwing error message

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I cloned the CLI repo and installed it using npm install -g . Then when I run any dw command, I get this:

D:\Projects\Dynamicweb\Cli>dw --help
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'yargs' imported from D:\Projects\Dynamicweb\Cli\bin\index.js
←[90m    at new NodeError (node:internal/errors:371:5)←[39m
←[90m    at packageResolve (node:internal/modules/esm/resolve:884:9)←[39m
←[90m    at moduleResolve (node:internal/modules/esm/resolve:929:18)←[39m
←[90m    at defaultResolve (node:internal/modules/esm/resolve:1044:11)←[39m
←[90m    at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)←[39m
←[90m    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)←[39m
←[90m    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)←[39m
←[90m    at link (node:internal/modules/esm/module_job:75:36)←[39m {
  code: ←[32m'ERR_MODULE_NOT_FOUND'←[39m
}

Is there maybe an installation instruction missing?

Also, do you want reports of issues for the CLI tool here or on github?

Imar

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Imar

Yes, issues on Github is perfect.

You need to run "npm install" after clone to get dependencies.

Later when the CLI is released as NPM package, that step will go away.

BR Nicolai

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Oh, you did run install....?

The node module is missing from a path that is available. Check this one out: https://sebhastian.com/npm-cannot-find-module/

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

And you ran the install from here?

D:\Projects\Dynamicweb\Cli>
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

>> Oh, you did run install....?

Yep

>> And you ran the install from here?

Yep

I fixed it by running npm i yargs manually. Looks like that dependency is not installed automatically when running npm install -g . and the installation steps doesn't mention this.

Now when I run dw I get this:

C:\Users\Imar>dw
Environment: undefined
file:///D:/Projects/Dynamicweb/Cli/bin/index.js:43
            console.log(`User: ${getConfig()?.env[getConfig()?.current?.env]?.current?.user}`)
                                                 ^

TypeError: Cannot read properties of undefined (reading 'undefined')
    at Object.handler (file:///D:/Projects/Dynamicweb/Cli/bin/index.js:43:50)
    at D:\Projects\Dynamicweb\Cli\node_modules\yargs\build\index.cjs:1:8891
    at j (D:\Projects\Dynamicweb\Cli\node_modules\yargs\build\index.cjs:1:4956)
    at M.handleValidationAndGetResult (D:\Projects\Dynamicweb\Cli\node_modules\yargs\build\index.cjs:1:8860)
    at M.applyMiddlewareAndGetResult (D:\Projects\Dynamicweb\Cli\node_modules\yargs\build\index.cjs:1:9502)
    at M.runCommand (D:\Projects\Dynamicweb\Cli\node_modules\yargs\build\index.cjs:1:7231)
    at Xt.[runYargsParserAndExecuteCommands] (D:\Projects\Dynamicweb\Cli\node_modules\yargs\build\index.cjs:1:58273)
    at Xt.parse (D:\Projects\Dynamicweb\Cli\node_modules\yargs\build\index.cjs:1:40011)
    at file:///D:/Projects/Dynamicweb/Cli/bin/index.js:35:6
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)

C:\Users\Imar>

which I think means that the tool is now working but the environment is null or so.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Is it worth exploring this further at this point or should I wait for a new version?

When I log in with an unknown user, I get this:

SyntaxError: Unexpected token < in JSON at position 4
    at JSON.parse (<anonymous>)
    at Response.json (file:///D:/Projects/Dynamicweb/Cli/node_modules/node-fetch/src/body.js:149:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async getToken (file:///D:/Projects/Dynamicweb/Cli/bin/commands/login.js:159:17)
    at async login (file:///D:/Projects/Dynamicweb/Cli/bin/commands/login.js:126:16)
    at async loginInteractive (file:///D:/Projects/Dynamicweb/Cli/bin/commands/login.js:100:17)
    at async file:///D:/Projects/Dynamicweb/Cli/bin/commands/login.js:95:13
    at async interactiveLogin (file:///D:/Projects/Dynamicweb/Cli/bin/commands/login.js:74:5)

it took me about 7 tries before I had an account working. Part of that seems caused by new users. I created a new user but couldn't use that to log in. Is that because of encrypted passwords maybe?

Then once set up (just running dw gives me an environment and a user), I tried to list files using dw files -l: which gave me this:

file:///D:/Projects/Dynamicweb/Cli/bin/commands/files.js:74
        let files = (await getFilesStructure(env, user, argv.dirPath, argv.recursive, argv.includeFiles)).model;
                                                                                                          ^

TypeError: Cannot read properties of undefined (reading 'model')
    at handleFiles (file:///D:/Projects/Dynamicweb/Cli/bin/commands/files.js:74:107)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

In the JSON response I see references to 'Unauthorized' and Bearer error="invalid_token" so I guess logging in didn't work.

My solution is up and running and I can log in to the backend using the user and password I give to the DW tool. The .dwc file lists my environment, user and host, but no API token.

Any ideas? Happy to wait testing further if this is too unstable for now.

Imar

 

 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Tried it again with a known user and got this:

Response {
  size: 0,
  [Symbol(Body internals)]: {
    body: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    stream: PassThrough {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null
    },
    boundary: null,
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    type: 'default',
    url: 'https://localhost:44360/Admin/Api/ApiKeySave',
    status: 415,
    statusText: 'Unsupported Media Type',
 
  headers: {
      connection: 'close',
      'content-type': 'application/problem+json; charset=utf-8',
      date: 'Wed, 12 Oct 2022 09:57:09 GMT',
      dw_user: 'Administrator, 2',
      server: 'Microsoft-IIS/10.0',
      'set-cookie': 'DW_Session_ID=2aca8c41f8e44401ad0f3df1669bf72b690a850684844e5eafc38639f3ee99970d1d66212caf45c4a486870aedbd2763; path=/; samesite=strict; httponly',
      'transfer-encoding': 'chunked',
      'x-powered-by': 'ASP.NET'
    },
    counter: 0,
    highWaterMark: 16384
  }
}

Looks like an issue with media types. Is this a change maybe in Alpha 7 or 8?

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Imar

Yes, I believe this is a change from 7-8 related to the management API that now needs a json document instead of a form post. We will look into it.

BR Nicolai

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Github has been updated - so new version should work with new management api format.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Great. It's now authenticating. However, there's a lot of other stuff that doesn't work so  I have openend a number of Github issues.

Thanks!

Imar

 

You must be logged in to post in the forum