scottdurow / dataverse-gen

Early-bound types generator for CDS/Dataverse
MIT License
20 stars 9 forks source link

TokenCache not found while initiating dataverse-gen #28

Closed albercl closed 1 year ago

albercl commented 1 year ago

I logged in Dataverse and generated the token, but when I try to execute npx dataverse-gen init I get the following error:

node:internal/modules/cjs/loader:988
  throw err;
  ^

Error: Cannot find module 'dataverse-ify/lib/xrm-webapi/TokenCache'
Require stack:
- C:\Users\alber\AppData\Roaming\npm\node_modules\dataverse-gen\lib\index.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (C:\Users\alber\AppData\Roaming\npm\node_modules\dataverse-gen\lib\index.js:19:22)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\alber\\AppData\\Roaming\\npm\\node_modules\\dataverse-gen\\lib\\index.js'
  ]
}

I also tried to move this file inside the node_modules folder and then it works, but I would prefer to not to do this. When I change node_modules\dataverse-gen\lib\index.js line 19 from const TokenCache_1 = require("dataverse-ify/lib/xrm-webapi/TokenCache"); to const TokenCache_1 = require("dataverse-ify/lib/webapi/TokenCache"); it works fine.

VERSION: 1.0.13

scottdurow commented 1 year ago

Hi @albercl - This is probably down to you having both version 1 and version 2 installed.

Can you use: npm uninstall -g dataverse-auth npm uninstall -g dataverse-ify npm uninstall -g dataverse-gen

Then try again? What version does it prompt you to install?

albercl commented 1 year ago

When I installed the packages I just ran npm dataverse-ify and npm dataverse-gen so it's supposed to download the latests versions. This versions are:

I tryed installing dataverse-auth using npm install dataverse-auth but is the same version that is included with dataverse-gen.

My situation right now is that I tryed installing dataverse-ify and dataverse-gen in a new project (I don't have them installed globally) and the error still appears. I detected that the error appears because it tries to import the token cache from dataverse-ify/lib/xrm-webapi/TokenCache while the real import path is dataverse-ify/lib/webapi/TokenCache. I also tried to change the import path of the dataverse-gen package to the correct one and then it works fine. Maybe the releases publised to npm aren't updated or aligned?

The specific line is index.ts#9 that is import { loadTokenCache } from "dataverse-ify/lib/xrm-webapi/TokenCache"; but should be import { loadTokenCache } from "dataverse-ify/lib/webapi/TokenCache";. At least, I changed it on the compiled JS and it worked as expected.

khoait commented 1 year ago

I'm using the same versions and having the same error as @albercl .

I notice latest versions on npm are 1.x not 2.x. Is it correct @scottdurow ?

janis-veinbergs commented 1 year ago

Wanted to test out dataverse-ify and npm is broken for me too. Tried to remove globals, noticed still using something from %appdata%\npm-cache deleted that, installed only locally, etc, etc, but always not working.

So the way I did get it to work is something like this (writing on top of my head):

mkdir dataverseify-test
cd dataverseify-test
mkdir libs
cd libs
git clone https://github.com/scottdurow/dataverse-auth.git
git clone https://github.com/scottdurow/dataverse-ify.git
git clone https://github.com/scottdurow/dataverse-gen.git
cd ..
# Will error out if no such dir created before generating types
mkdir -p src\dataverse-gen
npm init

Add workspaces to package.json:

"workspaces": [
    "libs/*"
  ],
npm install --save .\libs\dataverse-ify\
npm install --save-dev .\libs\dataverse-gen\
npm install --save-dev .\libs\dataverse-auth\

And then thiss stuff works and is on latest version:

npx dataverse-auth
npx dataverse-gen init

So what this does is creates a monorepo where those 3 libs are coming not from node modules, but from packages within libs directory

humanoidcreature commented 1 year ago

Had the same issue when followed the dataverse-ify's QuickStart wiki page. It installed the 1.x version of everything. But to fix it, you just have to edit your package.json and add the 2.x version. "dependencies": { "dataverse-gen": "^2.0.15", "dataverse-ify": "^2.0.7", "dataverse-auth": "^2.0.7" } Then just run npm install and do the authentiacation and dataverse-gen init again.