jeanfortheweb / typeorm-fixture-builder

Painless and type safe data fixtures for typeorm
MIT License
32 stars 5 forks source link

Unable to run CLI with npm #28

Closed Tim-mhn closed 3 years ago

Tim-mhn commented 3 years ago

Hi,

Thanks for the package 👍 I was looking for a solution from TypeORM to seed data into a db but it seems they don't have built-in solutions.

It works fine with yarn. But we are using NPM in my project and I have been able to use the CLI with npm :/

  1. I first tried to run these commands:

npm fixtures install npm typeorm-fixture-builder install

And i get the following errors (basically the command doesn't exist):

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview
  1. Also tried this one (inspired from the command for TypeORM migration):

ts-node ./node_modules/typeorm-fixture-builder/bin/cli.js install

In that case, i get this error:

Error: Cannot find module 'typescript'
Require stack:
- /home/timhn/projects/fermesdavenir/fermesdavenir/server/node_modules/typeorm-fixture-builder/node_modules/ts-node/dist/index.js
- /home/timhn/projects/fermesdavenir/fermesdavenir/server/node_modules/typeorm-fixture-builder/node_modules/ts-node/register/index.js
- /home/timhn/projects/fermesdavenir/fermesdavenir/server/node_modules/typeorm-fixture-builder/lib/cjs/cli.js
- /home/timhn/projects/fermesdavenir/fermesdavenir/server/node_modules/typeorm-fixture-builder/bin/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1020:15)
    at Function.resolve (internal/modules/cjs/helpers.js:78:19)
    at loadCompiler (/home/timhn/projects/fermesdavenir/fermesdavenir/server/node_modules/typeorm-fixture-builder/node_modules/ts-node/src/index.ts:375:30)
    at create (/home/timhn/projects/fermesdavenir/fermesdavenir/server/node_modules/typeorm-fixture-builder/node_modules/ts-node/src/index.ts:381:26)
    at Object.register (/home/timhn/projects/fermesdavenir/fermesdavenir/server/node_modules/typeorm-fixture-builder/node_modules/ts-node/src/index.ts:349:19)
    at Object.<anonymous> (/home/timhn/projects/fermesdavenir/fermesdavenir/server/node_modules/typeorm-fixture-builder/node_modules/ts-node/register/index.js:1:16)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14) `

Any tips would be glady appreciated, thanks again !

jeanfortheweb commented 3 years ago

Hello @Tim-mhn, thanks for the issue and a happy new year! I was not available in december, but I will look into this. Did you use "npm run" on the first part or just "npm"? It's strange that npm seems not to find typescript though.

jeanfortheweb commented 3 years ago

Closed due to inactivity

Tim-mhn commented 3 years ago

Hi @jeanfortheweb,

Sorry didn't see your reply. I ended up using the programmatic method with a script similar to what you suggest in your Readme. That works perfectly !

I was running just "npm" and any command such as npm fixtures --help would retrieve this error message

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

So it doesn't recognize the command.

Any command with npm run would retrieve the following :

npm ERR! missing script: fixtures

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/timhn/.npm/_logs/2021-01-22T09_49_16_452Z-debug.log

And that's a predictable error as there's no "fixtures" script in my package.json file.

Tim-mhn commented 3 years ago

Hey, nevermind I was dumb. Just had to use npx instead of npm.

Command npx fixtures install works as intended ;)

jeanfortheweb commented 3 years ago

Hello Tim! Thanks for that, I guess we should update the README for npm/npx users just to clarify.