Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container is falsy after upgrading to latest #112

Closed
tzellman opened this issue May 30, 2020 · 27 comments
Closed

Container is falsy after upgrading to latest #112

tzellman opened this issue May 30, 2020 · 27 comments
Labels

Comments

@tzellman
Copy link

tzellman commented May 30, 2020

Hello! After a proposed renovatebot bump to ember-cli-babel 7.20.3 (and thus 2.13.3 of babel-plugin-ember-modules-api-polyfill) I am seeing the following error:

ERROR Summary:
   - broccoliBuilderErrorStack: ReferenceError: /build/REDACTED/pods/socket/service.js: Container is falsy
     at NodePath._replaceWith (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/replacement.js:166:11)
     at NodePath.replaceWith (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/replacement.js:156:8)
     at /build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:180:33
     at Array.forEach (<anonymous>)
     at /build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:178:38
     at Array.forEach (<anonymous>)
     at PluginPass.ImportDeclaration (/build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:113:22)
     at newFn (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/visitors.js:179:21)
     at NodePath._call (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/context.js:55:20)
     at NodePath.call (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/context.js:42:17)
   - code: [undefined]
   - codeFrame: /build/REDACTED/pods/socket/service.js: Container is falsy
   - errorMessage: REDACTED/pods/socket/service.js: /build/REDACTED/pods/socket/service.js: Container is falsy
         in /tmp/broccoli-19l10NBMMp20Pg/out-621-analyzer_ember_auto_import_analyzer
         at broccoli-persistent-filter:Babel > [Babel: REDACTED] (Babel: REDACTED)
   - errorType: Build Error
   - location:
     - column: [undefined]
     - file: REDACTED/pods/socket/service.js
     - line: [undefined]
     - treeDir: /tmp/broccoli-19l10NBMMp20Pg/out-621-analyzer_ember_auto_import_analyzer
   - message: REDACTED/pods/socket/service.js: /build/REDACTED/pods/socket/service.js: Container is falsy
         in /tmp/broccoli-19l10NBMMp20Pg/out-621-analyzer_ember_auto_import_analyzer
         at broccoli-persistent-filter:Babel > [Babel: REDACTED] (Babel: REDACTED)
   - name: Error
   - nodeAnnotation: Babel: REDACTED
   - nodeName: broccoli-persistent-filter:Babel > [Babel: REDACTED]
   - originalErrorMessage: /build/REDACTED/pods/socket/service.js: Container is falsy
   - stack: ReferenceError: /build/REDACTED/pods/socket/service.js: Container is falsy
     at NodePath._replaceWith (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/replacement.js:166:11)
     at NodePath.replaceWith (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/replacement.js:156:8)
     at /build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:180:33
     at Array.forEach (<anonymous>)
     at /build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:178:38
     at Array.forEach (<anonymous>)
     at PluginPass.ImportDeclaration (/build/node_modules/ember-cli-babel/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:113:22)
     at newFn (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/visitors.js:179:21)
     at NodePath._call (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/context.js:55:20)
     at NodePath.call (/build/node_modules/ember-cli-babel/node_modules/@babel/traverse/lib/path/context.js:42:17)

The project does not use TypeScript, and is otherwise an up-to-date Ember 3.19 app.

The imports in socket/service.js are:

image

@rwjblue
Copy link
Member

rwjblue commented May 30, 2020

@tzellman thank you for reporting! Is there any way that you could help me identify what usage inside the file is causing the issue? Either by sharing the rest of the file contents (here or privately), or slowly deleting contents until it builds properly. Basically, some usage pattern that I haven’t properly accounted for is trigger this and I need to figure out what that is so we can fix it.

@tzellman
Copy link
Author

Sure thing! I honestly wasn't sure if this was the right place to report this (I was considering posting on Discord, but decided to keep the audience more targeted).

I apologize for not giving much context or repro'ing outside of a private repo, but I can get you that shortly!

@rwjblue
Copy link
Member

rwjblue commented May 30, 2020

Awesome, thank you! I don't fully grok what triggers this 🤔

@rwjblue
Copy link
Member

rwjblue commented May 30, 2020

For context, the error that is being thrown is from:

https://github.com/babel/babel/blob/31b361b736ee519180f9ea341e2a3e4e710d2ef4/packages/babel-traverse/src/path/replacement.js#L189-L191

Which is when we are calling .replaceWith here:

binding.referencePaths.forEach((referencePath) => {
if (!isTypescriptNode(referencePath.parentPath)) {
referencePath.replaceWith(getMemberExpressionFor(global));
}
});

@tzellman
Copy link
Author

Ok, here are some more details I should have provided up front, and may have helped isolate the issue:

  • only failing when running tests with COVERAGE=true (using ember-cli-code-coverage 1.0.0-beta.9); when I disabled this, I did not see the error
  • my coverage.json is pasted below
'use strict';

module.exports = {
    useBabelInstrumenter: true
};
  • I attempted to set useBabelInstrumenter to false and still received the error

I will share a repo shortly.

@rwjblue
Copy link
Member

rwjblue commented May 30, 2020

Hmm, interesting. I wonder if this is an interop issue between babel-plugin-istanbul and this one. Basically, this plugin is attempting to rewrite the imported identifiers (the ones from @ember/* modules) to the old-school globals APIs, but babel-plugin-istanbul (which is what ember-cli-code-coverage uses) is also rewriting the contents of the file (this is how they do instrumentation).

@rwjblue
Copy link
Member

rwjblue commented May 30, 2020

I attempted to set useBabelInstrumenter to false and still received the error

I don't think that flag does anything anymore:

https://github.com/kategengler/ember-cli-code-coverage/search?q=useBabelInstrumenter&type=Code

@rwjblue rwjblue added the bug label May 30, 2020
@tzellman
Copy link
Author

Thanks for the info!

I pushed a repo that demonstrates the error: https://github.com/tzellman/repro-112

There are some unnecessary deps, and I likely could reproduce in a simpler fashion, but hopefully this helps to see the main Ember-related dependencies.

Let me know if there is something I should try to help out here. 👍

@tzellman
Copy link
Author

I was able to "resolve" the issue in my sample repo by making the following change:

image

@gitKrystan
Copy link

gitKrystan commented Jun 3, 2020

We are seeing this issue too, on a dependabot PR upgrading ember-cli-babel from 7.20.0 to 7.20.4 (so babel-plugin-ember-modules-api-polyfill from 2.13.0 to 2.13.3). Indeed, turning off code coverage fixed the issue, and the model in question uses Evented.

@caass
Copy link

caass commented Jun 10, 2020

For anyone else who comes here looking for a workaround, I was able to get it working using yarn resolutions, since my project didn't directly depend on this package, and only included it as the dependency of a dependency

package.json:

{
  "name": "blah",
  "private": true
  "dependencies": {
    // etc
  },
  "resolutions": {
    "babel-plugin-ember-modules-api-polyfill": "2.13.0"
  }
}

@brunoocasali
Copy link

brunoocasali commented Jun 18, 2020

In my case, I'm have ember-cli-code-coverage in 1.0.0.beta-9 too, and the problem started happen after I ran the suggested command yarn upgrade:

dash git:(master)  yarn run test:cov --server
yarn run v1.22.4
$ LINTER=false COVERAGE=true ember test --server
Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade`

Then after the command when I try to run the tests:

- broccoliBuilderErrorStack: ReferenceError: /builds/trustvox/dash.js/dash/services/filters.js: Container is falsy
     at NodePath._replaceWith (/builds/trustvox/dash.js/node_modules/@babel/traverse/lib/path/replacement.js:166:11)
     at NodePath.replaceWith (/builds/trustvox/dash.js/node_modules/@babel/traverse/lib/path/replacement.js:156:8)
     at /builds/trustvox/dash.js/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:173:33
     at Array.forEach (<anonymous>)
     at /builds/trustvox/dash.js/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:171:38
     at Array.forEach (<anonymous>)
     at PluginPass.ImportDeclaration (/builds/trustvox/dash.js/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:106:22)
     at newFn (/builds/trustvox/dash.js/node_modules/@babel/traverse/lib/visitors.js:179:21)
     at NodePath._call (/builds/trustvox/dash.js/node_modules/@babel/traverse/lib/path/context.js:55:20)
     at NodePath.call (/builds/trustvox/dash.js/node_modules/@babel/traverse/lib/path/context.js:42:17)
   - code: [undefined]
   - codeFrame: /builds/trustvox/dash.js/dash/services/filters.js: Container is falsy
   - errorMessage: dash/services/filters.js: /builds/trustvox/dash.js/dash/services/filters.js: Container is falsy
         in /tmp/broccoli-79liy212tJVnKl/out-462-analyzer_ember_auto_import_analyzer
         at broccoli-persistent-filter:Babel > [Babel: dash] (Babel: dash)
   - errorType: Build Error
   - location:
     - column: [undefined]
     - file: dash/services/filters.js
     - line: [undefined]
     - treeDir: /tmp/broccoli-79liy212tJVnKl/out-462-analyzer_ember_auto_import_analyzer
   - message: dash/services/filters.js: /builds/trustvox/dash.js/dash/services/filters.js: Container is falsy
         in /tmp/broccoli-79liy212tJVnKl/out-462-analyzer_ember_auto_import_analyzer
         at broccoli-persistent-filter:Babel > [Babel: dash] (Babel: dash)
   - name: Error
   - nodeAnnotation: Babel: dash
   - nodeName: broccoli-persistent-filter:Babel > [Babel: dash]
   - originalErrorMessage: /builds/trustvox/dash.js/dash/services/filters.js: Container is falsy
   - stack: ReferenceError: /builds/trustvox/dash.js/dash/services/filters.js: Container is falsy
     at NodePath._replaceWith (/builds/trustvox/dash.js/node_modules/@babel/traverse/lib/path/replacement.js:166:11)
     at NodePath.replaceWith (/builds/trustvox/dash.js/node_modules/@babel/traverse/lib/path/replacement.js:156:8)
     at /builds/trustvox/dash.js/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:173:33
     at Array.forEach (<anonymous>)
     at /builds/trustvox/dash.js/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:171:38
     at Array.forEach (<anonymous>)
     at PluginPass.ImportDeclaration (/builds/trustvox/dash.js/node_modules/babel-plugin-ember-modules-api-polyfill/src/index.js:106:22)
     at newFn (/builds/trustvox/dash.js/node_modules/@babel/traverse/lib/visitors.js:179:21)
     at NodePath._call (/builds/trustvox/dash.js/node_modules/@babel/traverse/lib/path/context.js:55:20)
     at NodePath.call (/builds/trustvox/dash.js/node_modules/@babel/traverse/lib/path/context.js:42:17)
 =================================================================================

My service/filters.js contents are:

import Service from '@ember/service';
import Evented from '@ember/object/evented';
import { A } from '@ember/array';
import { tracked } from '@glimmer/tracking';
import { computed } from '@ember/object';

export default class FiltersService extends Service.extend(Evented) {
  ...
}

After trying to remove some parts of the file (including the whole class body) without success, I've removed the import of Evented and the Service.extend(Evented) part, and the errors disappears.

Hope it helps ;)

@apellerano-pw
Copy link

I ran into this issue today after regenerating package-lock.json, and sub dependencies reached for [email protected]. (We don't use this package directly.)

It happens only when I run coverage generation via ember-cli-code-coverage. I could reproduce with both 1.0.0-beta.8 and 1.0.0-beta.9. Didn't try others.

My stack traces look like everyone else's, but we are still on Ember 3.4 using the old class syntax, so the file in question contains this line:

const PipelineLoaderArray = EmberObject.extend(EmberArray, {

Wanted to share because I'm using a different Mixin (EmberArray) than the other reports (Evented). Perhaps it's something about the Mixin syntax in general causing the issue.

When I remove the Mixin, coverage runs as expected. (But changes app behavior.)

const PipelineLoaderArray = EmberObject.extend({

We aren't using yarn, so as a workaround I pinned this package to 2.13.0 in my package.json. I also had to prevent our ember-cli-babel dependency from going higher than 7.20.0, as that's the last time it allowed for this package to be 2.13.0.

@Gorzas
Copy link

Gorzas commented Jun 25, 2020

@apellerano-pw I'm having the same issue and your solution isn't working for me 😢. I'm using Ember v3.7.3.

@apellerano-pw
Copy link

@Gorzas try npm ls babel-plugin-ember-modules-api-polyfill, it will show you what version of this dep your packages are using in node_modules. If it says 2.13.4 you will hit the bug. Here's the versions of everything that are working from me (taken from above command and also npm ls ember-cli-babel)

├─┬ [email protected]
│ └── [email protected]

├─┬ [email protected]
│ └── [email protected]  deduped

@jrock2004
Copy link

So the only thing that would work for me is to turn off code coverage tool

chrisvdp added a commit to chrisvdp/ember-cli-babel that referenced this issue Jul 24, 2020
@rreckonerr
Copy link

rreckonerr commented Aug 18, 2020

Having the same error here! 😩
Unfortunately, adding babel-plugin-ember-modules-api-polyfill to yarn resolutions doesn't help.

Any progress on solving this issue? Hitting it both on 3.20 and 3.16.

@rreckonerr
Copy link

Can confirm that this aslo affects extending from RSVP

import classic from "ember-classic-decorator";
import EmberObject from "@ember/object";
import RSVP from "rsvp";

@classic
export default class Rsvp extends EmberObject.extend(RSVP) {}

@pete-the-pete
Copy link

If i use yarn resolutions for babel-plugin-ember-modules-api-polyfill I end up with the following after running COVERAGE=true ember build:

⠋ Building[broccoli-persistent-filter:Babel > [Babel: global-utils]: Babel: global-utils] was configured to `throwUnlessParallelizable` and was unable to parallelize a plugin. 
plugins:
1: name: unknown, location: node_modules/babel-plugin-istanbul,
↓ function source ↓ 
(api, options, dirname) => {
    if (!api.assertVersion) {
      api = Object.assign(copyApiObject(api), {
        assertVersion(range) {
          throwVersionError(range, api.version);
        }

@rahsheen
Copy link

rahsheen commented Sep 9, 2020

Just wondering if there's any resolution on this. We do not use yarn and it seems like the resolutions path may or may not even be a work-around. What can we do here?

@chrisvdp
Copy link

chrisvdp commented Sep 9, 2020

For a temporary workaround, I forked ember-cli-babel and forced a working version of the package.

chrisvdp/ember-cli-babel@dc8a5bd

Then reference my fork in my package.json

"ember-cli-babel": "chrisvdp/ember-cli-babel#dc8a5bdf53e1c118cc897444e0629502048094b4",

@Cjewett
Copy link

Cjewett commented Oct 21, 2020

Any updates here? The package.json resolution fix isn't applicable for us due to other packages requiring later versions than 2.13.0 (ember-cli-babel 7.21+ requirement). Is there anything with the reproduce project in here that people should try that might produce more information to fix this bug?

@rwjblue
Copy link
Member

rwjblue commented Oct 23, 2020

I still think the thing I mentioned above is what is going on: there is a conflict between our modules import rewriting and babel-plugin-istanbul that causes the istanbul plugin from running on an object that no longer has a container (in the AST heirarchy), but I haven't had much time to dig in here. 😩

@jrock2004
Copy link

@rwjblue Any tips to help a person who might not know where to look to try to help?

@mukilane
Copy link

mukilane commented Oct 27, 2020

Another temporary workaround for those who cannot afford to change the package versions, try excluding the lines/files that cause the issue from istanbul coverage.

/* istanbul ignore next */
const PipelineLoaderArray = EmberObject.extend(EmberArray, {
/* istanbul ignore next */
export default class FiltersService extends Service.extend(Evented) {

It worked for my case, without any other changes or packages.

Ref: https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md

@rwjblue
Copy link
Member

rwjblue commented Oct 27, 2020

I think a good next step is a failing test PR here, we have a few examples of "works with xyz plugin" in the test suite already so this should basically match those but use the Istanbul plugin.

@rwjblue
Copy link
Member

rwjblue commented Feb 11, 2021

Fixed by @mdeanjones over in #156 (thank you!!!!!!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests