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

Error when using [email protected] with staticAddonTrees enabled #396

Closed
makepanic opened this issue Feb 24, 2020 · 10 comments
Closed

Error when using [email protected] with staticAddonTrees enabled #396

makepanic opened this issue Feb 24, 2020 · 10 comments

Comments

@makepanic
Copy link

makepanic commented Feb 24, 2020

Hi,

when enabling staticAddonTrees in an app that uses [email protected], I'm seeing an error being thrown:

Could not find module `@ember-data/model/-private` imported from `(require)`
data-version ok
3.15.0 🆗
3.15.1 🆗
3.16.0 👎
3.17.0-beta.0 👎

Reproduction repo: https://github.com/makepanic/embroider-data-staticAddonTrees

If this issue is better tracked in the ember-data repo, I can reopen it there.

@Gaurav0
Copy link

Gaurav0 commented Feb 24, 2020

This may have to do with the work being done to make @ember-data/model optional. @runspired ?

@runspired
Copy link

@Gaurav0 its due to embroider doing special sauce things for EmberData that it should not be doing. There’s a way for embroider users to opt out.

@ef4
Copy link
Contributor

ef4 commented Feb 24, 2020

Yes, older versions of ember-data broke under embroider so there's a compat adapter. But the new versions work and don't need the adapter and the adapter breaks them.

Try this as a workaround until I can release a version that does this automatically:

const { Webpack } = require('@embroider/webpack');
return require('@embroider/compat').compatBuild(app, Webpack, {
  compatAdapters: new Map([['ember-data', null]])
});

@makepanic
Copy link
Author

Thanks for the response.

I've changed it to add compatAdapters: new Map([['ember-data', null]]), but it seems to still throw the same error.

@atsjj
Copy link

atsjj commented Apr 10, 2020

I managed to get this working with [email protected].

You can try the workaround with the following ember-cli-build.js:

'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const { V1Addon } = require('@embroider/compat');
const { forceIncludeModule } = require('@embroider/compat/src/compat-utils');

class EmberDataCompatAdapter extends V1Addon {
  get packageMeta() {
    return forceIncludeModule(super.packageMeta, './-private');
  }
}

module.exports = function(defaults) {
  let app = new EmberApp(defaults, {
    // Add options here
  });

  // Use `app.import` to add additional libraries to the generated
  // output files.
  //
  // If you need to use different assets in different
  // environments, specify an object as the first parameter. That
  // object's keys should be the environment name and the values
  // should be the asset to use in that environment.
  //
  // If the library that you are including contains AMD or ES6
  // modules that you would like to import into your application
  // please specify an object with the list of modules as keys
  // along with the exports of each module as its value.

  const { Webpack } = require('@embroider/webpack');
  return require('@embroider/compat').compatBuild(app, Webpack, {
    compatAdapters: new Map([
      ['@ember-data/model', EmberDataCompatAdapter],
      ['@ember-data/record-data', EmberDataCompatAdapter],
    ]),
    staticAddonTestSupportTrees: true,
    staticAddonTrees: true,
    staticComponents: true,
    staticHelpers: true,
  });
};

This change seemed to have an effect on the DEBUG directories. Forcefully including the -private paths for the two modules did the following:

diff -qr DEBUG-BROKEN DEBUG-WORKING

Only in DEBUG-WORKING/ember-cli-babel/@ember/test-helpers: 017
Only in DEBUG-WORKING/ember-cli-babel/@ember/test-helpers: 018
Only in DEBUG-WORKING/ember-cli-babel/@ember/test-helpers: 029
Only in DEBUG-WORKING/ember-cli-babel/@ember/test-helpers: 030
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/adapter: 006
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/adapter: 007
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/canary-features: 005
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/canary-features: 006
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/canary-features: 011
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/canary-features: 012
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/debug: 010
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/debug: 016
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/model: 011
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/model: 018
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/model: 019
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/private-build-infra: 004
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/private-build-infra: 008
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/record-data: 012
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/record-data: 021
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/record-data: 022
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/serializer: 013
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/serializer: 024
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/serializer: 025
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/store: 009
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/store: 014
Only in DEBUG-WORKING/ember-cli-babel/@ember-data/store: 015
Only in DEBUG-WORKING/ember-cli-babel/ember-data: 003
Only in DEBUG-WORKING/ember-cli-babel/ember-data: 004
Only in DEBUG-WORKING/ember-cli-babel/ember-fetch: 014
Only in DEBUG-WORKING/ember-cli-babel/ember-fetch: 015
Only in DEBUG-WORKING/ember-cli-babel/ember-fetch: 026
Only in DEBUG-WORKING/ember-cli-babel/ember-fetch: 027
Only in DEBUG-WORKING/ember-cli-babel/ember-load-initializers: 016
Only in DEBUG-WORKING/ember-cli-babel/ember-load-initializers: 028
Only in DEBUG-WORKING/ember-data: ember-data

My best guess is that the tooling doesn't like that the @ember-data/model addon as well as the @ember-data/record-data addon rollup the -private module and then exclude that from the addon tree. I'm still learning how embroider works and I'm unable to suggest a fix better than my hack at this time. However, I hope this helps!

@NullVoxPopuli
Copy link
Collaborator

I had the same issue with ember-data 3.18, and the above comment/hack fixed it for me

@NullVoxPopuli
Copy link
Collaborator

NullVoxPopuli commented Apr 29, 2020

also, this works, if not using the meta package:

      compatAdapters: new Map([
        ['@ember-data/debug', null],
        ['@ember-data/model', null],
        ['@ember-data/store', null],
        ['@ember-data/record-data', null],
      ]),

probably just ['ember-data', null] if using the meta package.
thanks @runspired ! <3

However, this does not work (with these specific options:

  return compatBuild(app, Webpack, {
      extraPublicTrees: additionalTrees,
      staticAddonTestSupportTrees: true,
      staticAddonTrees: true, // having this enabled requires that we use the EmberDataCompatAdapter custom class
      staticHelpers: true,
      staticComponents: true,
      // splitAtRoutes: true,
      // skipBabel: [],
      packageRules: [
        {
          package: 'ember-intl',
          semverRange: '^4.3.2',
          addonModules: {
            'services/intl.js': {
              dependsOnModules: ['../adapters/default.js']
            }
          }
        },
      ],
      compatAdapters: new Map([
        ['@ember-data/model', null],
        ['@ember-data/model', null],
        ['@ember-data/store', null],
        ['@ember-data/record-data', null],
      ]),
    });

@runspired
Copy link

@NullVoxPopuli enabling staticAddonTrees causes embroider to try to follow import statements to decide what to include.

Unfortunately, things like @ember-data/debug and @ember-data/model are designed by @ember-data/store to only import conditionally.

Embroider has a solution for these in the long term (the embroider spec introduces conditional imports that it understands) but we don't use these in EmberData yet as we need to support the traditional ember-cli environment. Our plan is to convert to them once it is possible (which may already be the case but wasn't when I last examined).

@mkszepp
Copy link
Contributor

mkszepp commented Mar 7, 2022

i think this problem was solved in embroider 1.2. (see https://github.com/embroider-build/embroider/blob/v1.2.0/CHANGELOG.md#v120-2022-02-10 / pull request #1124)

@ef4 ef4 closed this as completed Mar 7, 2022
@rreckonerr
Copy link

Seems like the issue is still there. I'm on ember-data version 4.4. None of the solutions above help.

"@embroider/compat": "^1.6.0",
"@embroider/core": "^1.6.0",
"@embroider/router": "^1.8.3",
"@embroider/webpack": "^1.6.0"

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

No branches or pull requests

8 participants