ember.js: TemplateCompiler `cannot read property 'visitor' of undefined`
I’m currently diagnosing an issue that cropped up with the recent ember-canary/ember-beta’s (todays), it may not be a bug with Ember.js itself, but rather some other part of our default system that is now getting tripped up.
Stack Strace:
TypeError: Cannot read property 'visitor' of undefined
at preprocess (/private/var/folders/9n/_xy74rdd4m3063fr5kqdl5vc000mw4/T/embroider/cb03bb/packages/router/node_modules/ember-source/vendor/ember/ember-template-compiler.js:12246:42)
at normalize (/private/var/folders/9n/_xy74rdd4m3063fr5kqdl5vc000mw4/T/embroider/cb03bb/packages/router/node_modules/ember-source/vendor/ember/ember-template-compiler.js:12906:15)
at precompileJSON (/private/var/folders/9n/_xy74rdd4m3063fr5kqdl5vc000mw4/T/embroider/cb03bb/packages/router/node_modules/ember-source/vendor/ember/ember-template-compiler.js:5402:47)
at precompile (/private/var/folders/9n/_xy74rdd4m3063fr5kqdl5vc000mw4/T/embroider/cb03bb/packages/router/node_modules/ember-source/vendor/ember/ember-template-compiler.js:5435:31)
at Object.precompile (/private/var/folders/9n/_xy74rdd4m3063fr5kqdl5vc000mw4/T/embroider/cb03bb/packages/router/node_modules/ember-source/vendor/ember/ember-template-compiler.js:19197:37)
at NodeTemplateCompiler.precompile (/Users/spenner/src/embroider-build/embroider/packages/core/src/template-compiler-common.js:71:36)
at NodeTemplateCompiler.compile (/Users/spenner/src/embroider-build/embroider/packages/core/src/template-compiler-common.js:87:47)
at NodeTemplateCompiler.compile (/Users/spenner/src/embroider-build/embroider/packages/core/src/template-compiler-node.js:23:25)
at Object.hbsLoader (/Users/spenner/src/embroider-build/embroider/packages/hbs-loader/src/index.js:9:16)
at LOADER_EXECUTION (/Users/spenner/src/embroider-build/embroider/node_modules/loader-runner/lib/LoaderRunner.js:132:14)
```
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 15 (6 by maintainers)
Ok. Solution: Ensure your template compiler plugins follow the new form only.
In my case, ember-cli-template-lint’s plugins where simply incompatible with the new plugin form introduced by https://github.com/glimmerjs/glimmer-vm/commit/28652d4ea214f1c7bf0251d4b4b23853d9f0a787, and required upgrading to
ember-template-lint. Given thatember-cli-template-lintis deprecated, in this scenario it is likely perfectly reasonable solution.That being said, the debugging on this is quite sub-optimal, and I although I hope folks running into this problem at helped by this issue, i suspect (assuming the above is a reasonable change) that better detection of the failure mode could go a long way. Specifically https://github.com/glimmerjs/glimmer-vm/blob/ef92c497c3d921af22b38a54eac1445c204c3370/packages/%40glimmer/syntax/lib/parser/tokenizer-event-handlers.ts#L447 could detect a return value without
{ visitor() { } }and provide throw an actionable error@JenLyndle The issue with
ember-cp-validationsis most likely due to the deprecation that was cleaned up in #19429 for disallowing legacy class-based AST plugins. It looks like @Turbo87 fixed this issue in qonto/ember-cp-validations#3, but that’s a fork of the addon that doesn’t appear to be published to NPM. The original addon hasn’t been touched since April 2021.@npendery I finally managed to figure out what was causing the ember 4 build to fail for me. Due to some reason, using ember-cp-validations library was breaking the code. Removing it and all related code helped the build to succeed. Need to go back and figure out how to get around the problem. Just wanted to give you a heads up in case you are using this library.
It appears the deprecated
ember-cli-template-lintis not compatible with ember-source 4x. Specifically because one of it’s plugins’s constructor is now being interpreted as a plugin most likely due to https://github.com/glimmerjs/glimmer-vm/commit/28652d4ea214f1c7bf0251d4b4b23853d9f0a787 and possibly https://github.com/emberjs/ember.js/commit/bbb62dde664772ae5ce75b460ce878ed758747cdNow it seems pretty reasonable that a deprecated plugin causes a failure, but it isn’t clear yet if this effects non-deprecated plugins, and also the debugging of this wasn’t ideal.
I’ll dig in some more…