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

Cannot find module package.json #19

Closed
krasnoukhov opened this issue Sep 22, 2017 · 11 comments
Closed

Cannot find module package.json #19

krasnoukhov opened this issue Sep 22, 2017 · 11 comments

Comments

@krasnoukhov
Copy link

I'm seeing this weird issue on v1.0.3. It's not reproducible on v0.3.1

Error: The Broccoli Plugin: [BroccoliMergeTrees: Addon#compileAddon(ember-attacher) ] failed with:
Error: Cannot find module '/project/node_modules/ember-attacher/node_modules/babel-plugin-filter-imports/lib//package.json'

The integration code is here, which looks perfectly normal to me:

https://github.com/kybishop/ember-attacher/blob/a2f1cd0850c4afc6b371cf121ff35138e4c0eca3/index.js#L35-L43

Any help would be appreciated. Thanks

@kybishop
Copy link

This error persists even after changing the configuration to the new style. For now we are downgrading back to 0.3.1.

@layershifter
Copy link
Collaborator

Thanks for report guys. Let's try to resolve it.

new configuration

There where changes in configuration, do you followed this?

-babelOptions.plugins.push([FilterImports, strippedImports]);
+babelOptions.plugins.push([FilterImports, {
  imports: strippedImports
}]);

New version of plugin also removes imports, you can to do this:

-babelOptions.plugins.push([FilterImports, strippedImports]);
-babelOptions.plugins.push([RemoveImports, 'ember-attacher/-debug/helpers']);
+babelOptions.plugins.push([FilterImports, {
+  keepImports: false,
+  imports: strippedImports
+}]);

ES6 exports

You're requiering module as CommonJS, but this plugin was rewritten in ES6, so you need to make following change:

-const FilterImports = require('babel-plugin-filter-imports');
+const FilterImports = require('babel-plugin-filter-imports').default;

Can you try to make these changes?

@kybishop
Copy link

@layershifter it works! Looks like something is a bit off though, getting a giant warning message from ember s and ember b:

ember s -prod
Livereload server on http://localhost:49153
broccoli-babel-transpiler is opting out of caching due to a plugin that does not provide a caching strategy: `function () {
  return {
    visitor: {
      ImportDeclaration: function ImportDeclaration(path, _ref) {
        var opts = _ref.opts;
        var imports = opts.imports,
            _opts$keepImports = opts.keepImports,
            keepImports = _opts$keepImports === undefined ? false : _opts$keepImports;
        var _path$node = path.node,
            source = _path$node.source,
            specifiers = _path$node.specifiers;

        var members = _lodash2.default.get(imports, _lodash2.default.get(source, 'value'));

        /*
         * Heads up! This condition omits processing of non-filtered imports.
         */
        if (!members) return;

        var specifiersForRemoval = (0, _getSpecifierNames2.default)(members, specifiers);
        var specifierNames = _lodash2.default.map(specifiersForRemoval, 'local.name');

        _lodash2.default.forEach(specifierNames, function (specifier) {
          return (0, _removeReferences2.default)(path, specifier);
        });

        if (keepImports) return false;
        if (specifiers.length === specifierNames.length) {
          path.remove();
          return;
        }

        _lodash2.default.set(path, 'node.specifiers', _lodash2.default.without.apply(_lodash2.default, [specifiers].concat(_toConsumableArray(specifiersForRemoval))));
      }
    }
  };
}`.

@krasnoukhov
Copy link
Author

@layershifter Thanks for your help! It's really appreciated. I'm wondering if the new syntax documented somewhere? Because it's not on the README and it feels like having it there would've prevented this whole hiccup 😆 I'm not a great technical writer, but let me know if you could use my help here

@layershifter
Copy link
Collaborator

Thanks for the feedback. It seems that I need to restore CommonJS export. I've made a branch with it, can you grab code from there and test?

Your import should be also restored to:

const FilterImports = require('babel-plugin-filter-imports');

@kybishop
Copy link

Hey @layershifter, I'm seeing the same error as originally posted with the given branch, regardless of using .default or not on the require.

I'm using the following entry in ember-attacher's package.json:

"babel-plugin-filter-imports": "git+https://git@github.com/ember-cli/babel-plugin-filter-imports.git#310499784b25ccbf598b62392dfacd35de93e59b",

@layershifter
Copy link
Collaborator

@kybishop can you make a manual for me? How I can test it? Possible minimal repo or something another?

@kybishop
Copy link

@layershifter I just pushed my WIP branch for updating babel-plugin-filter-imports: https://github.com/kybishop/ember-attacher/tree/update-babel-plugin-filter-imports

You can test with ember s -prod. Note that babel-plugin-filter-imports is only used in the prod build.

@layershifter
Copy link
Collaborator

layershifter commented Sep 26, 2017

@kybishop Can you check the latest? As I see it works fine and I make cleanups and release patch.

"babel-plugin-filter-imports": "git+https://git@github.com/ember-cli/babel-plugin-filter-imports.git#8140dfedc35afc51ba66486c80a4c8d8e6efd09b"

BTW, thanks for the cooperation and patience 👍

@kybishop
Copy link

Success! Thanks @layershifter

@layershifter
Copy link
Collaborator

Released in babel-plugin-filter-imports@1.0.4. Thanks again 👍

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

3 participants