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 use import statement outside a module #21

Open
AddisonG opened this issue Oct 30, 2019 · 4 comments
Open

Cannot use import statement outside a module #21

AddisonG opened this issue Oct 30, 2019 · 4 comments

Comments

@AddisonG
Copy link

AddisonG commented Oct 30, 2019

After installing the module with sudo npm install ember-i18n-intl-migrator -g, I get the following error when running it (no args):

SyntaxError: Cannot use import statement outside a module
    at new Function (<anonymous>)
    at Object.<anonymous> (/usr/local/lib/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:12:15)
    at Array.forEach (<anonymous>)
    at module.exports (/usr/local/lib/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:10:11)
    at Object.<anonymous> (/usr/local/lib/node_modules/ember-i18n-intl-migrator/bin/ember-i18n-intl-migrator.js:10:3)
    at Module._compile (internal/modules/cjs/loader.js:971:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1011:10)
    at Module.load (internal/modules/cjs/loader.js:822:32)
    at Function.Module._load (internal/modules/cjs/loader.js:730:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1051:12)

I tried changing directories, from the base ember folder, but just got:

Error: ENOENT: no such file or directory, scandir 'app/locales'

Which makes sense. Thus, I must be in the correct directory, but something else is going wrong.
This also happens when I install the module as a local user, along ember-i18n (not globally), and run it from the node_modules folder.

Node Version: v13.0.1
Operating System: Ubuntu 18.04.3 LTS

@snewcomer
Copy link
Contributor

That first error seems like it might be app related code. Not sure where we are using import in translation-transform.js

@rreckonerr
Copy link

@AddisonG did you figure out how to deal with this error eventually?

@AddisonG
Copy link
Author

@rreckonerr - No, sorry. If I recall correctly, a few of us at work dug down into the code, and found what appeared to be the root cause, but decided against attempting to fix it, since it wasn't worth the effort.

@AddisonG
Copy link
Author

AddisonG commented May 18, 2020

Took another look at this @rreckonerr and @snewcomer. The problem seems to be that we were importing other generated json files into translations.js, like so:

import external_import from './example';

export default {
    "first": {
        "key": "value"
    },
    "second": external_import
}

This caused it to fail on this line:

let obj = new Function(content.replace('export default', 'return'))();

The workaround is to manually resolve all the imports, by pasting the contents into the translations.js file, so that it has no import statements or code other than the export default line.

It would be nice to have this work for when multiple files are used, but that's a feature more than a bugfix.

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