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

i18n throwing error on async/await syntax #3

Closed
rabeesh opened this issue Apr 1, 2018 · 24 comments
Closed

i18n throwing error on async/await syntax #3

rabeesh opened this issue Apr 1, 2018 · 24 comments

Comments

@rabeesh
Copy link

rabeesh commented Apr 1, 2018

i18n throwing error on async/await syntax

module.exports = () => {
    return async ({
        shop
    }) => {
        await someExample();
    };
};

The code throws error at

Line 4: Unexpected token function (line 4)
@papandreou
Copy link
Member

Hi @rabeesh, could you provide a bit of context? Are you using assetgraph-i18n with assetgraph-builder? Which version(s)?

@rabeesh
Copy link
Author

rabeesh commented Apr 1, 2018

Found the issue could you update, assetgraph on dependencies into latest??

https://github.com/assetgraph/assetgraph-i18n/blob/master/package.json#L27

Please update into "assetgraph": "4.1.0" . I think this will solve async/await Unexpected token => error

@papandreou
Copy link
Member

Ah, thanks. I did that and released 0.4.0.

However, I think assetgraph should have been a peer dep instead so that it'll always use the one that assetgraph-builder comes with. I made that change as well and released 0.5.0.

It would be a nice help if you could try out both :)

@rabeesh
Copy link
Author

rabeesh commented Apr 1, 2018

With these change, AssetGraph.query is undefined which throwing error

/node_modules/assetgraph-i18n/bin/checkLanguageKeys:96
        followRelations: query.or(
                               ^
TypeError: Cannot read property 'or' of undefined

https://github.com/assetgraph/assetgraph-i18n/blob/master/bin/checkLanguageKeys#L45

@papandreou
Copy link
Member

Hmm, looks like there's a bit of work associated with adapting to assetgraph 4. Will take a look soon.

@papandreou
Copy link
Member

Could you try 0.6.0?

@Mahesh434
Copy link

now facing an issue while installing package.

npm ERR! path /project/node_modules/assetgraph-i18n/applyBabelJob.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/webshopbackend/node_modules/assetgraph-i18n/applyBabelJob.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

@papandreou
Copy link
Member

@Mahesh434, ah, stupid typo of mine in package.json. Try 0.6.1 :)

@Mahesh434
Copy link

Tried but having this issue :(

/project/node_modules/assetgraph-i18n/bin/checkLanguageKeys.js:167
  .prettyPrintAssets({ type: ['I18n'], isDirty: true })
   ^

TypeError: (intermediate value).logEvents(...).loadAssets(...).bundleWebpack(...).populate(...).bundleSystemJs(...).bundleRequireJs(...).populate(...).queue(...).if(...).prettyPrintAssets is not a function
    at Object. (/project/node_modules/assetgraph-i18n/bin/checkLanguageKeys.js:167:4)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
make: *** [checklanguagekeys] Error 1

@papandreou
Copy link
Member

Ah, there aren't any tests of the checkLanguageKeys.js binary. I know how to fix that, will do it tonight :)

@papandreou
Copy link
Member

Should be fixed in 0.6.2 :)

@rabeesh
Copy link
Author

rabeesh commented Apr 9, 2018

Still make checklanguagekeys throwing error Unknown node type AssignmentPattern for default function parameter eg:

function inlineAssignment(locale = 'en_us') {
    ....
}

will throw error Unknown node type AssignmentPattern

If remove default parameter, then no error showing up

function inlineAssignment(locale) {
    locale = locale ||  'en_us';
}

I have checked in esprima , look like they are supporting this feature.

papandreou added a commit that referenced this issue Apr 9, 2018
@papandreou
Copy link
Member

Looks like that error is coming out of estraverse or something. I'm a little unsure about how to reproduce it. Could you tell me a bit about the setup? Are you using the webpack, system.js, or require.js integration? What's the exact command that terminates with that error? Could you share the complete output, and is there a stack trace, etc.?

@Mahesh434
Copy link

we are using require.js integraion
here is the error:
✔ 0.002 secs: logEvents ✔ 1.377 secs: loadAssets ℹ INFO: Webpack is installed, but could not load the webpack config (tried http-files/webpack.config.js): Cannot find module 'http-files/webpack.config.js' ✔ 0.764 secs: bundleWebpack ✔ 0.096 secs: populate ✔ 0.013 secs: bundleSystemJs { Error: Error: ERROR: module path does not exist: /xyz/bootstrapper.js for module named: /xyz/bootstrapper.js. Path is relative to: /project at /project/node_modules/assetgraph/node_modules/requirejs/bin/r.js:28441:35

@Mahesh434
Copy link

I think the problem is with the lib: escodegen which is using older version of esprima (3.xx). If we manual change esprima to 4.0.0 in package.json of escodegen then loading assets is working with no issues.

papandreou added a commit that referenced this issue Apr 15, 2018
Trying to address: #3 (comment)
@papandreou
Copy link
Member

Hmm, weird, escodegen only seems to use esprima in a binary that we don't use. It must be some secondary effect of having the old esprima available in assetgraph-i18n or assetgraph.

I've tried adding a dependency on esprima ^4.0.0 in assetgraph-i18n in the hope that it helps. Could you try assetgraph-i18n 0.7.0?

@rab1
Copy link

rab1 commented Jan 24, 2019

Still getting following errors with "assetgraph-i18n": "0.7.1",

Unknown node type RestElement.
Unknown node type Super.
Unknown node type AssignmentPattern.

I think some of issues will resolved, when moving into upcoming esprima version v5.0 jquery/esprima#1743.

@papandreou
Copy link
Member

Hmm, it’s probably the estraverse fork that doesn’t support these nodes. I’m busy this week but will try to take a look soon.

@papandreou
Copy link
Member

I don't really have enough info to make a test case, but I think this is due to estools/estraverse#95 not being merged. I added a workaround (inspired by estools/estraverse#97 (comment)) and published 0.7.2. Could you see if that helped?

papandreou added a commit that referenced this issue Jan 26, 2019
Should avoid the error described in
#3 (comment)
until estools/estraverse#95 gets merged.
@rab1
Copy link

rab1 commented Jan 29, 2019

Still getting the error, the ./node_modules/assetgraph/lib/assets/JavaScript.js is referring to the estraverse-fb , that internally pointing to estraverse@1.9.3.

Please see the error stack

Error: Unknown node type AssignmentPattern.
    at Controller.traverse (/home/rab/one-apps/webshopbackend/node_modules/estraverse/estraverse.js:517:31)
    at Object.traverse (/home/rab/one-apps/webshopbackend/node_modules/estraverse/estraverse.js:709:27)
    at JavaScript.findOutgoingRelationsInParseTree (/home/rab/one-apps/webshopbackend/node_modules/assetgraph/lib/assets/JavaScript.js:354:16)
    at JavaScript.get outgoingRelations [as outgoingRelations] (/home/rab/one-apps/webshopbackend/node_modules/assetgraph/lib/assets/Asset.js:1075:38)
    at JavaScript.populate (/home/rab/one-apps/webshopbackend/node_modules/assetgraph/lib/assets/Asset.js:1312:12)
    at JavaScript.load (/home/rab/one-apps/webshopbackend/node_modules/assetgraph/lib/assets/Asset.js:515:14)
    at <anonymous>

the assetgraph-i18n using assetgraph@5.4.1

@rab1
Copy link

rab1 commented Jan 29, 2019

Found workaround by install into packages by npm install --save-dev estraverse@latest, which installed estraverse@4.2.0 .

May be the order of estraverse installed cause this issue !

@papandreou
Copy link
Member

Hmm, weird, does it work if you remove the direct estraverse dependency in your app, then rm -fr node_modules && npm i?

Which version of assetgraph-builder are you using?

@rab1
Copy link

rab1 commented Jan 30, 2019

@papandreou Yeah, already tried rm -rf node_modules && npm cache clean -f && npm i

@papandreou
Copy link
Member

npm i assetgraph-builder assetgraph-i18n
$ npm ls estraverse
/Users/andreaslind/work/throwaway
├─┬ assetgraph-builder@6.4.3
│ ├─┬ assetgraph@5.4.1
│ │ ├─┬ escodegen-papandreou@1.11.0-patch1
│ │ │ └── estraverse@4.2.0  deduped
│ │ └── estraverse@4.2.0  deduped
│ └── estraverse@4.2.0 
└─┬ assetgraph-i18n@0.7.2
  ├─┬ esmangle@1.0.1
  │ ├─┬ escope@1.0.3
  │ │ └── estraverse@2.0.0  extraneous
  │ ├─┬ esshorten@1.1.1
  │ │ └── estraverse@4.1.1  extraneous
  │ └── estraverse@1.5.1  extraneous
  └── estraverse@4.2.0  deduped

It seems like the latest published version of esmangle depends on estraverse@~1.5.0: https://github.com/estools/esmangle/blob/8f48a7631380623182e0e11ba02b0c5743ecdbf9/package.json#L30

We should be able to find out if that's causing it if you try applying this patch in your project:

patch -p1
--- a/node_modules/assetgraph-i18n/lib/i18nTools.js
+++ b/node_modules/assetgraph-i18n/lib/i18nTools.js
@@ -81,7 +81,7 @@ function foldConstant(node) {
         }
       ]
     };
-    const foldedNode = esmangle.optimize(wrappedNode);
+    const foldedNode = wrappedNode;
     const valueNode = foldedNode.body[0].declarations[0].init;
     if (valueNode.type === 'Literal' && typeof valueNode.value === 'string') {
       return valueNode;
^D

... then try building 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

4 participants