datocms / cli

Official CLI to interact with DatoCMS projects!
MIT License
7 stars 7 forks source link

When running migration:new an error occurs #11

Closed mtsbarbosa closed 1 year ago

mtsbarbosa commented 1 year ago

My version:

datocms --help            
CLI to interact with DatoCMS APIs

VERSION
  @datocms/cli/1.0.20 darwin-arm64 node-v17.9.1

When running datocms migrations:new 'create article model' the following error occurs:

datocms migrations:new 'create article model'
 ›   ModuleLoadError: [MODULE_NOT_FOUND] require failed to load /Users/my-user/.nvm/versions/node/v17.9.1/lib/node_modules/@datocms/cli/lib/commands/migrations/new.js: Cannot find module 
 ›   '/Users/my-user/.nvm/versions/node/v17.9.1/lib/node_modules/@datocms/cli/node_modules/browser-or-node/lib/index.js'. Please verify that the package.json has a valid "main" entry
 ›   Code: MODULE_NOT_FOUND

Indeed, I dont see browser-or-node as a dependency in the package.json of datocms@cli

stefanoverna commented 1 year ago

Mh, I cannot seem to be able to reproduce it :(

Btw, browser-or-node is a sub-dependency (@datocms/cli -> @datocms/cma-client-node -> browser-or-node), so that's why you don't see it in package.json

$ nvm install 17
Downloading and installing node v17.9.1...
Downloading https://nodejs.org/dist/v17.9.1/node-v17.9.1-darwin-x64.tar.xz...
Now using node v17.9.1 (npm v8.11.0)

$ nvm use 17
Now using node v17.9.1 (npm v8.11.0)

$ npm install -g @datocms/cli
added 200 packages, and audited 201 packages in 11s

33 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

$ datocms --help
CLI to interact with DatoCMS APIs

VERSION
  @datocms/cli/1.0.20 darwin-x64 node-v17.9.1

$ datocms migrations:new 'create article model' --api-token=XXX
Writing "migrations/1670064548_createArticleModel.js"... done
mtsbarbosa commented 1 year ago

Hi @stefanoverna sorry, the problem in the end was that I installed the datocms cli using node 11 (with nvm) after installing, you have the cli totally bounded to the node you picked during the installation and you are unable to make it work in another So I had to go to the node_modules folder from .nvm and delete the datocms cli, reinstalling that at the right node version Not sure if there is something to be done here, probably not, feel free to close it in that case3