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

Module parse failed #397

Closed
RemiKalbe opened this issue Jul 25, 2018 · 9 comments
Closed

Module parse failed #397

RemiKalbe opened this issue Jul 25, 2018 · 9 comments

Comments

@RemiKalbe
Copy link

RemiKalbe commented Jul 25, 2018

vue & vue-i18n version

vue : 2.5.16 (I'm using the cli)
vue-i18n : 8.0.0

Reproduction Link

https://github.com/RemiVillien/VueI18nError

Steps to reproduce

npm run serve

What is Expected?

No ERROR

What is actually happening?


Module parse failed: Unexpected token i in JSON at position 0 while parsing near 'import mod from "-!....'
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token i in JSON at position 0 while parsing near 'import mod from "-!....'
    at JSON.parse (<anonymous>)
    at parseJson (/usr/src/app/node_modules/json-parse-better-errors/index.js:7:17)
    at JsonParser.parse (/usr/src/app/node_modules/webpack/lib/JsonParser.js:16:16)
    at doBuild.err (/usr/src/app/node_modules/webpack/lib/NormalModule.js:443:32)
    at runLoaders (/usr/src/app/node_modules/webpack/lib/NormalModule.js:325:12)
    at /usr/src/app/node_modules/loader-runner/lib/LoaderRunner.js:370:3
    at iterateNormalLoaders (/usr/src/app/node_modules/loader-runner/lib/LoaderRunner.js:211:10)
    at /usr/src/app/node_modules/loader-runner/lib/LoaderRunner.js:183:6
    at runSyncOrAsync (/usr/src/app/node_modules/loader-runner/lib/LoaderRunner.js:130:11)
    at /usr/src/app/node_modules/loader-runner/lib/LoaderRunner.js:175:3
    at loadLoader (/usr/src/app/node_modules/loader-runner/lib/loadLoader.js:36:3)
    at iteratePitchingLoaders (/usr/src/app/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
    at runLoaders (/usr/src/app/node_modules/loader-runner/lib/LoaderRunner.js:362:2)
    at NormalModule.doBuild (/usr/src/app/node_modules/webpack/lib/NormalModule.js:263:3)
    at NormalModule.build (/usr/src/app/node_modules/webpack/lib/NormalModule.js:410:15)
    at Compilation.buildModule (/usr/src/app/node_modules/webpack/lib/Compilation.js:616:10)

 @ ./src/App.vue 21:0-126 22:11-17 22:34-40
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://172.17.0.2:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

Hi,

I don't want to bother but I really don't understand why I get this error, I only get that when I add <i18n src='./locales/en-US.json'></i18n> to any .vue file.
I'm prety sure I did something wrong but I just don't understand what it is.
I hope you can help me 🙏

@kimuraz
Copy link
Contributor

kimuraz commented Jul 25, 2018

Hi @RemiVillien, I guess it shouldn't work because <i18n> is a component, so in your case, it shouldn't be included outside the <template> tag:
https://github.com/RemiVillien/VueI18nError/blob/5d6434f78747872b068b338b2803bf3fdb02ca5d/src/App.vue#L1
Take a look at the example in the documentation here

@RemiKalbe
Copy link
Author

Thanks you, I don't get the error anymore.
I did like you told me

<template>
   <div id="app">
       <i18n src='./locales/en-US.json'></i18n>
       <LogOrSign />
   </div>
</template>

But now I get

[vue-i18n] Cannot translate the value of keypath 'login'. Use the value of keypath as default

What have I done wrong again ><

@RemiKalbe
Copy link
Author

Oh, and I also get [Vue warn]: Missing required prop: "path" 2 times

@RemiKalbe
Copy link
Author

RemiKalbe commented Jul 25, 2018

Ok I figured it out, I don't think it's the right way, but it works

const messages = {
    "en-US": require("./locales/en-US.json"),
    "fr-FR": require("./locales/fr-FR.json")
};

const i18n = new VueI18n({
    locale: navigator.language,
    fallbackLocale: 'en-US',
    messages
});

@desprit
Copy link

desprit commented Jul 31, 2018

I'm having same issue.
I added plugin to my config file:
https://kazupon.github.io/vue-i18n/guide/sfc.html#vue-cli-3-0-beta

It says that we can use i18n outside of template:
https://kazupon.github.io/vue-i18n/guide/sfc.html#multiple-custom-blocks

<i18n src="@/locales/ui.json"></i18n>

Module parse failed: Unexpected token i in JSON at position 0 while parsing near 'import mod from "-!....'

@RemiKalbe RemiKalbe reopened this Jul 31, 2018
@kazupon
Copy link
Owner

kazupon commented Jul 31, 2018

seem same #401 issue

@desprit
Copy link

desprit commented Jul 31, 2018

@kazupon
Yes :)

@5pilow
Copy link

5pilow commented Aug 26, 2018

Hello, I am facing the exact same problem, any news about a fix? Thank you!

@Tahusyed
Copy link

Tahusyed commented Nov 6, 2023

Facing same issue
at JSXParser.Parser.parseObjectProperty (C:\Users\C92507\AppData\Roaming\npm\node_modules@vue\cli\node_modules\esprima\dist\esprima.js:2534:25)
at JSXParser.Parser.parseObjectInitializer (C:\Users\C92507\AppData\Roaming\npm\node_modules@vue\cli\node_modules\esprima\dist\esprima.js:2602:35)
at JSXParser.Parser.inheritCoverGrammar (C:\Users\C92507\AppData\Roaming\npm\node_modules@vue\cli\node_modules\esprima\dist\esprima.js:2285:37)
at JSXParser.Parser.parsePrimaryExpression (C:\Users\C92507\AppData\Roaming\npm\node_modules@vue\cli\node_modules\esprima\dist\esprima.js:2354:38)
at JSXParser.parsePrimaryExpression (C:\Users\C92507\AppData\Roaming\npm\node_modules@vue\cli\node_modules\esprima\dist\esprima.js:466:97)

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

6 participants