opral / monorepo

globalization ecosystem && change control SDK
https://opral.com
Apache License 2.0
1.17k stars 96 forks source link

[bug] Unexpected end of JSON input when using `plugin-json` #1123

Closed dalton5 closed 1 year ago

dalton5 commented 1 year ago

Problem

Hi,

I can't have the extension to work. Neither tootip nor commands are working.

I have this error:

image

My config:

image

Expected behavior

It should find the command and the extension should work

Reproduction

Install the extension inlang

inlang.config.js file

/**
* @type { import("@inlang/core/config").DefineConfig }
*/
export async function defineConfig(env) {
    const { default: jsonPlugin } = await env.$import('https://cdn.jsdelivr.net/npm/@inlang/plugin-json@3/dist/index.js');

    const { default: standardLintRules } = await env.$import('https://cdn.jsdelivr.net/npm/@inlang/plugin-standard-lint-rules@3/dist/index.js');

    return {
        referenceLanguage: 'en',
        plugins: [
            jsonPlugin({ pathPattern: 'client/locales/{language}.json' }),
            standardLintRules(),
        ],
    };
}

npx @inlang/cli config validate file

npx @inlang/cli config validate

 ERROR  (node:24388) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time  13:36:15  
(Use `node --trace-warnings ...` to show where the warning was created)

files                                                                                                                      13:36:16
files                                                                                                                      13:36:16
files                                                                                                                      13:36:16
files                                                                                                                      13:36:16

 ERROR  The inlang.config.js is invalid.                                                                                   13:36:16  

# The following errors occurred during the setup of plugins:

None ✅

# The following errors occurred during the validation of the config:

Unexpected end of JSON input

---

If plugins return errors, chances are high that the plugin errors are the root cause
for the config errors. Try to fix the plugin errors first.

  # The following errors occurred during the setup of plugins:

  None ✅

  # The following errors occurred during the validation of the config:

  Unexpected end of JSON input

  ---

  If plugins return errors, chances are high that the plugin errors are the root cause
  for the config errors. Try to fix the plugin errors first.

  at setupConfig (/xxxx/node_modules/@inlang/cli/dist/main.js:68914:11)
  at async getConfig (/xxxx/node_modules/@inlang/cli/dist/main.js:69029:19)
  at async Command2.validateCommandAction (/xxxx/node_modules/@inlang/cli/dist/main.js:70686:37)

Other information

image

Windows 11

NilsJacobsen commented 1 year ago

@inlang/ide-extension

felixhaeberle commented 1 year ago

@dalton5 It seems to me that your json file can't be parsed correctly. Can you share your json? Or the structure of it?

dalton5 commented 1 year ago

en.json

{
  "home": "Home",
  "an-error-has-happened-during-the-launch": "An error has happened during the launch",
  "our-villas": "Our lodges",
  "your-journey": "Your journey",
  "local-advices": "Local Advices",
  "gallery": "Gallery",
  "contact": "Contact",
  "booking": "Booking",
  "from": "from",
  "night": "$ / Night",
  "room-facilities": "Room Facilities",
  "services": "Services",
  "we-are": "Services at",
  "citronelles": "Citronnelles",
  "choose-room": "Discover our lodges",
  "hotel-facilities": "Proposed Facilities",
  "latest": "Latest",
  "discover": "Discover",
  "our-gallery": "our Gallery",
  "book-now": "Book Now",
  "french": "French",
  "english": "English",
  "guided-tour": "Guided tour",
  "room-overview": "room overview",
  "select": "Select",
  "rooms": "Rooms",
  "relax-and-choose": "relax and choose",
  "visit": "Visit",
  "guests": "Guests",
  "sqm": "sqm",
  "send-us-message": "Send Us Message",
  "please-enter-your-name": "Please enter your name.",
  "please-enter-your-valid-e-mail-id": "Please enter your valid E-mail.",
  "make-a": "Make a",
  "address": "Address",
  "your-name": "Your Name",
  "your-email": "Your Email",
  "please-enter-your-phone-number": "Please enter your phone number.",
  "your-phone": "Your Phone",
  "please-enter-your-message": "Please enter your message.",
  "your-message": "Your Message",
  "your-message-has-been-sent-successfully": "Your message has been sent successfully.",
  "sorry-error-occured-this-time-sending-your-message": "Sorry, an error occured this time sending your message.",
  "your-message-has-been-sent-successfully-refresh-this-page-if-you-want-to-send-more-messages": "Your message has been sent successfully.",
  "sorry-there-was-an-error-sending-your-form": "Sorry there was an error sending your form.",
  "your-reservation-has-been-sent-successfully": "Your reservation has been sent successfully.",
  "send": "Send"
}
felixhaeberle commented 1 year ago

@dalton5 What is the installed version of node on your system? For inlang to work seamlessly, we recommend v18 or above. (only vscode is running on v16)

@NilsJacobsen Can you jump in here? I don't think this is an ide extension issue. The JSON looks correct for me but gives Unexpected end of JSON input.

dalton5 commented 1 year ago

v18.12.1 is installed on the system

NilsJacobsen commented 1 year ago

@dalton5 I need help seeing where the problem origins. Could you provide an open-sourced reproduction project? I know it requires some work from your side, but it helps to understand the error.

@inlang/plugins

dalton5 commented 1 year ago

Ok I found a new clue. I am going to check why he finds my config bad.

image

dalton5 commented 1 year ago

Ok I changed some stuff in the config and now I have this error

image

NilsJacobsen commented 1 year ago

@dalton5 I recommend starting with the npx @inlang/cli@latest config validate command. If that returns an error there should be either a setup problem between inlang.config.js and your recourse files or a bug in the plugin.

While this is not solved, you don't need to look in the ide-extension.

Could you provide us with your folder structure? I'm especially interested in the nesting of your resource files.

dalton5 commented 1 year ago

npx @inlang/cli@latest config validate

npx @inlang/cli@latest config validate

ERROR (node:40176) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time (Use node --trace-warnings ... to show where the warning was created)

i 🔎 Validating the config file... 16:40:19 √ 🎉 Inlang config is valid!

dalton5 commented 1 year ago

My inlang config is in client folder. Not the root. Is it an issue?

image

NilsJacobsen commented 1 year ago

@dalton5 that is the problem. The inlang.config.js needs to be in the root. more info -> https://inlang.com/documentation/quick-start#manual-step-by-step-guide

felixhaeberle commented 1 year ago

@dalton5 and, if you want to do yourself a favor, exclude node_modules via .gitignore 😅 you don't want to store 4k files in your repository on github.

samuelstroschein commented 1 year ago

@NiklasBuchfink can you run this repo https://github.com/dalton5/proofError on your windows machine and try to reproduce the bug?

NiklasBuchfink commented 1 year ago

I cloned the repo and tried it on my windows machine. Without changing the inlang.config.js it worked, but the @inlang/sdk-js uses the i function and the VS Code extension only recognizes the t function:

image

@felixhaeberle Do you know why this is the case?

dalton5 commented 1 year ago

Yes I could find the issue by putting inlang config file at the root.

But can you launch the page? if you run npm run dev and go to the page? I have an issue of multiple load.

NilsJacobsen commented 1 year ago

@ivanhofer smells like we need a dedicated sveltekit sdk plugin:D

felixhaeberle commented 1 year ago

@NilsJacobsen There is one, this can be seen as the "sveltekit" SDK plugin, because we only support sveltekit for now: https://github.com/inlang/inlang/blob/242fe2f0369d79faa5f149c60f4256b13790f285/source-code/sdk-js-plugin/README.md#L13

NiklasBuchfink commented 1 year ago

With or without the inlangPlugin() inside the vite.config.js, I just get a 500 error.

But it also seems that houdini and inlangPlugin use define both a load function which produce conflicts inside the vite:esbuild bundling:

Internal server error: Transform failed with 2 errors:
C:/Users/nikla/Documents/code/proofError/client/src/routes/+layout.server.ts:13:13: ERROR: Multiple exports with the same name "load"
C:/Users/nikla/Documents/code/proofError/client/src/routes/+layout.server.ts:13:13: ERROR: The symbol "load" has already been declared
  Plugin: vite:esbuild
  File: C:/Users/nikla/Documents/code/proofError/client/src/routes/+layout.server.ts:13:13

  Multiple exports with the same name "load"
  11 |  }
  12 |
  13 |  export const load = initRootLayoutServerLoadWrapper().use(() => {});
     |               ^

  The symbol "load" has already been declared
  11 |  }
  12 |
  13 |  export const load = initRootLayoutServerLoadWrapper().use(() => {});
     |               ^

      at failureErrorWithLog (C:\Users\nikla\Documents\code\proofError\client\node_modules\esbuild\lib\main.js:1646:15)
      at C:\Users\nikla\Documents\code\proofError\client\node_modules\esbuild\lib\main.js:847:29
      at responseCallbacks.<computed> (C:\Users\nikla\Documents\code\proofError\client\node_modules\esbuild\lib\main.js:703:9)
      at handleIncomingPacket (C:\Users\nikla\Documents\code\proofError\client\node_modules\esbuild\lib\main.js:762:9)
      at Socket.readFromStdout (C:\Users\nikla\Documents\code\proofError\client\node_modules\esbuild\lib\main.js:679:7)
      at Socket.emit (node:events:513:28)
      at addChunk (node:internal/streams/readable:324:12)
      at readableAddChunk (node:internal/streams/readable:297:9)
      at Readable.push (node:internal/streams/readable:234:10)
      at Pipe.onStreamRead (node:internal/stream_base_commons:190:23) (x2)
Error: Transform failed with 2 errors:
C:/Users/nikla/Documents/code/proofError/client/src/routes/+layout.server.ts:13:13: ERROR: Multiple exports with the same name "load"
C:/Users/nikla/Documents/code/proofError/client/src/routes/+layout.server.ts:13:13: ERROR: The symbol "load" has already been declared
    at failureErrorWithLog (C:\Users\nikla\Documents\code\proofError\client\node_modules\esbuild\lib\main.js:1646:15)
    at C:\Users\nikla\Documents\code\proofError\client\node_modules\esbuild\lib\main.js:847:29
    at responseCallbacks.<computed> (C:\Users\nikla\Documents\code\proofError\client\node_modules\esbuild\lib\main.js:703:9)
    at handleIncomingPacket (C:\Users\nikla\Documents\code\proofError\client\node_modules\esbuild\lib\main.js:762:9)
    at Socket.readFromStdout (C:\Users\nikla\Documents\code\proofError\client\node_modules\esbuild\lib\main.js:679:7)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23) {
  errors: [
    {
      detail: undefined,
      id: '',
      location: [Object],
      notes: [Array],
      pluginName: '',
      text: 'Multiple exports with the same name "load"'
    },
    {
      detail: undefined,
      id: '',
      location: [Object],
      notes: [Array],
      pluginName: '',
      text: 'The symbol "load" has already been declared'
    }
  ],
  warnings: [],
  frame: '\n' +
    '\x1B[33mMultiple exports with the same name "load"\x1B[39m\n' +
    '11 |  }\n' +
    '12 |  \n' +
    '13 |  export const load = initRootLayoutServerLoadWrapper().use(() => {});\n' +
    '   |               ^\n' +
    '\n' +
    '\x1B[33mThe symbol "load" has already been declared\x1B[39m\n' +
    '11 |  }\n' +
    '12 |  \n' +
    '13 |  export const load = initRootLayoutServerLoadWrapper().use(() => {});\n' +
    '   |               ^\n',
  loc: {
    column: 13,
    file: 'C:/Users/nikla/Documents/code/proofError/client/src/routes/+layout.server.ts',
    length: 4,
    line: 13,
    lineText: 'export const load = initRootLayoutServerLoadWrapper().use(() => {});',
    namespace: '',
    suggestion: ''
  },
  plugin: 'vite:esbuild',
  id: 'C:/Users/nikla/Documents/code/proofError/client/src/routes/+layout.server.ts',
  pluginCode: 'import { buildSessionObject } from "$houdini/plugins/houdini-svelte/runtime/session";\r\n' +
    'import { initRootLayoutServerLoadWrapper } from "@inlang/sdk-js/adapter-sveltekit/server";\r\n' +
    '\r\n' +
    'export async function load(event) {\r\n' +
    '    const __houdini__vite__plugin__return__value__ = {};\r\n' +
    '\r\n' +
    '    return {\r\n' +
    '        ...buildSessionObject(event),\r\n' +
    '        ...__houdini__vite__plugin__return__value__\r\n' +
    '    };\r\n' +
    '}\r\n' +
    '\r\n' +
    'export const load = initRootLayoutServerLoadWrapper().use(() => {});'
}
dalton5 commented 1 year ago

Just for ypour information it was an issue I created some months ago here: https://github.com/inlang/inlang/issues/878

NiklasBuchfink commented 1 year ago

@dalton5 Let's close this issue and reopen #878, as it appears to be a duplicate. @ivanhofer, can you continue there as you have more experience in Svelte and their "Vite" bundling process?