Giter Site home page Giter Site logo

Comments (10)

mattdsteele avatar mattdsteele commented on July 21, 2024 1

I just ran into this as well.

Problematic code:

export default function ($timeout) {
    'ngInject';
    //etc
}

Seems to resolve with:

const directive = function ($timeout) {
    'ngInject';
    //etc
};

export default directive;

from babel-plugin-angularjs-annotate.

MrSpider avatar MrSpider commented on July 21, 2024 1

I have a fix for this, but it's really hacky because of a bug in babel #5444.
As soon as my babel PR gets merged, I am gonna make a PR here to fix this issue.

from babel-plugin-angularjs-annotate.

kfeinUI avatar kfeinUI commented on July 21, 2024 1

I ended up taking babel-plugin-transform-export-default-name and extending it to additionally transform all function declarations into a separate named function which is then referenced by the export. By running that first, it makes it play nice with this plugin while also retaining function names

from babel-plugin-angularjs-annotate.

schmod avatar schmod commented on July 21, 2024

@lili21 Can you post the source code of the function causing problems?

from babel-plugin-angularjs-annotate.

lili21 avatar lili21 commented on July 21, 2024

or resolve with

export default function directive ($timeout) {
  'ngInject';
  ...
}

named function is required if you are using es2015 module.

also can be resolve with

module.exports = function ($timeout) {
  'ngInject';
  ....

from babel-plugin-angularjs-annotate.

mattdsteele avatar mattdsteele commented on July 21, 2024

Another workaround is to use an arrow function, a la:

export default ($timeout) => {
    'ngInject';
    //etc
};

from babel-plugin-angularjs-annotate.

kfeinUI avatar kfeinUI commented on July 21, 2024

Ran into this too. It's touchy when it comes to exports.

Would also be helpful if the errors provided a bit more information to help track down the issues. For example, if it doesn't know what to do with a node of a particular type then output the type and any other useful context.

from babel-plugin-angularjs-annotate.

schmod avatar schmod commented on July 21, 2024

Thanks @MrSpider, and for tracking down the root bug too!

from babel-plugin-angularjs-annotate.

nynexman4464 avatar nynexman4464 commented on July 21, 2024

Ran into this recently. babel-plugin-transform-export-default-name worked. I wanted to paste the stacktrace here because above is an image which made this really hard to google.

ERROR in ./~/security-match-builder/src/match-components/min-date.js
Module build failed: TypeError: /Users/arock/dev/portal-security-config-ui/node_modules/security-match-builder/src/match-components/min-date.js: Cannot read property 'name' of null
    at judgeInjectArraySuspect (/Users/arock/dev/portal-security-config-ui/node_modules/babel-plugin-angularjs-annotate/ng-annotate-main.js:769:58)
    at /Users/arock/dev/portal-security-config-ui/node_modules/babel-plugin-angularjs-annotate/ng-annotate-main.js:588:13
    at Array.forEach (native)
    at judgeSuspects (/Users/arock/dev/portal-security-config-ui/node_modules/babel-plugin-angularjs-annotate/ng-annotate-main.js:560:19)
    at PluginPass.exit (/Users/arock/dev/portal-security-config-ui/node_modules/babel-plugin-angularjs-annotate/babel-ng-annotate.js:148:11)
    at newFn (/Users/arock/dev/portal-security-config-ui/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/Users/arock/dev/portal-security-config-ui/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/arock/dev/portal-security-config-ui/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/arock/dev/portal-security-config-ui/node_modules/babel-traverse/lib/path/context.js:117:8)
    at TraversalContext.visitQueue (/Users/arock/dev/portal-security-config-ui/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/arock/dev/portal-security-config-ui/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/arock/dev/portal-security-config-ui/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/Users/arock/dev/portal-security-config-ui/node_modules/babel-traverse/lib/index.js:114:17)
    at traverse (/Users/arock/dev/portal-security-config-ui/node_modules/babel-traverse/lib/index.js:79:12)
    at File.transform (/Users/arock/dev/portal-security-config-ui/node_modules/babel-core/lib/transformation/file/index.js:558:35)
    at /Users/arock/dev/portal-security-config-ui/node_modules/babel-core/lib/transformation/pipeline.js:50:19
    at File.wrap (/Users/arock/dev/portal-security-config-ui/node_modules/babel-core/lib/transformation/file/index.js:574:16)
    at Pipeline.transform (/Users/arock/dev/portal-security-config-ui/node_modules/babel-core/lib/transformation/pipeline.js:47:17)
    at transpile (/Users/arock/dev/portal-security-config-ui/node_modules/babel-loader/lib/index.js:46:20)
    at Object.module.exports (/Users/arock/dev/portal-security-config-ui/node_modules/babel-loader/lib/index.js:163:20)
 @ ./~/security-match-builder/src/match-components/index.js 11:0-50
 @ ./~/security-match-builder/src/security-match-builder.js
 @ ./src/app.js

from babel-plugin-angularjs-annotate.

schmod avatar schmod commented on July 21, 2024

fixed in 0.8.0

from babel-plugin-angularjs-annotate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.