angular-cli: Getting "Cannot find module" when trying to use custom schematics with `new` command
There’s little to no info about how to actually use schematics, so I tried forking @schematics/angular
, changed couple things, published on npm (https://www.npmjs.com/package/@thescrollbar/schematics / https://github.com/thescrollbar/schematics), did following https://github.com/nrwl/nx/tree/master/packages/schematics#installing-nrwlschematics and tried
ng new impr --collection=@thescrollbar/schematics
, which throws error listed below… in case you are wondering, that path does exist on my filesystem and does link to this https://github.com/thescrollbar/schematics/tree/master/application
I also tried publishing contents of https://github.com/angular/devkit/tree/master/packages/schematics/angular to npm without changing anything and use it as schematics, didn’t work either
Bug Report or Feature Request (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
@angular/cli: 1.4.2 node: 8.1.4 os: darwin x64
The log given by the failure.
Error: Cannot find module '/Users/fxck/.yarn-config/global/node_modules/@thescrollbar/schematics/application'
at Function.Module._resolveFilename (module.js:485:15)
at Function.resolve (internal/module.js:18:19)
at new ExportStringRef (/Users/fxck/.yarn-config/global/node_modules/@angular-devkit/schematics/tools/export-ref.js:15:32)
at NodeModulesEngineHost._resolveReferenceString (/Users/fxck/.yarn-config/global/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:18:21)
at NodeModulesEngineHost.createSchematicDescription (/Users/fxck/.yarn-config/global/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:92:34)
at SchematicEngine.createSchematic (/Users/fxck/.yarn-config/global/node_modules/@angular-devkit/schematics/src/engine/engine.js:63:40)
at CollectionImpl.createSchematic (/Users/fxck/.yarn-config/global/node_modules/@angular-devkit/schematics/src/engine/collection.js:11:29)
at Object.getSchematic (/Users/fxck/.yarn-config/global/node_modules/@angular/cli/utilities/schematics.js:40:23)
at Class.run (/Users/fxck/.yarn-config/global/node_modules/@angular/cli/tasks/schematic-get-options.js:12:40)
at Class.beforeRun (/Users/fxck/.yarn-config/global/node_modules/@angular/cli/commands/new.js:99:31)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 18 (3 by maintainers)
I can make it work this way: https://medium.com/@c1265a527848/95e22319cc24
I hope there’s going to be a way to set your collection as the default one so you don’t have to
use --collection=whatever
anytime you try to generate something.Yep. Still getting
tree.branch is not a function
, works if I install my package globally withnpm i -g @thescrollbar/schematics
and then manually move it from/usr/local/bin/node_modules/
to/usr/local/bin/node_modules/@angular/cli/node_modules
I think I figured out at least one part. I thought that cli would be able to work with typescript schematics, but it actually has to be compiled first. So instead of just cloning https://github.com/angular/devkit/tree/master/packages/schematics/angular you actually need to clone and work with its
npm run build
command, you can then start changingpackages/schematics/angular
, I suppose there’s a way to add your own schematics along it, but who knows on what places you need to chance stuff, so it’s safer to just change the angular one… then you publish the dist folder to npm and THEN you can use it as a collection… I have yet to try if I’ll encounter thetree.branch
problem.Barring documentation, it would be great if we could get some official feedback on whether or not we’re even intended to be using this stuff yet. I get the sense that it’s not production-ready for anything outside of the internal usage of it. But since there’s no official word on this one way or another, a lot of us are very confused.