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

Unexpected token y in JSON at position 0 #1

Open
thekevinbrown opened this issue Mar 10, 2020 · 7 comments
Open

Unexpected token y in JSON at position 0 #1

thekevinbrown opened this issue Mar 10, 2020 · 7 comments

Comments

@thekevinbrown
Copy link

This is what I'm getting when I run npx typescript-monorepo-toolkit inject-refs .:

❯ DEBUG=typescript-monorepo-toolkit npx typescript-monorepo-toolkit inject-refs .
npx: installed 15 in 1.755s
  typescript-monorepo-toolkit Running command inject-refs with { yarnWorkspaceRoot: '.',
  typescript-monorepo-toolkit   cmdObj:
  typescript-monorepo-toolkit    Command {
  typescript-monorepo-toolkit      commands: [],
  typescript-monorepo-toolkit      options: [ [Option] ],
  typescript-monorepo-toolkit      _execs: Set {},
  typescript-monorepo-toolkit      _allowUnknownOption: false,
  typescript-monorepo-toolkit      _args: [ [Object] ],
  typescript-monorepo-toolkit      _name: 'inject-refs',
  typescript-monorepo-toolkit      _optionValues: {},
  typescript-monorepo-toolkit      _storeOptionsAsProperties: true,
  typescript-monorepo-toolkit      _passCommandToAction: true,
  typescript-monorepo-toolkit      _actionResults: [],
  typescript-monorepo-toolkit      _helpFlags: '-h, --help',
  typescript-monorepo-toolkit      _helpDescription: 'output usage information',
  typescript-monorepo-toolkit      _helpShortFlag: '-h',
  typescript-monorepo-toolkit      _helpLongFlag: '--help',
  typescript-monorepo-toolkit      _noHelp: false,
  typescript-monorepo-toolkit      _exitCallback: undefined,
  typescript-monorepo-toolkit      _executableFile: undefined,
  typescript-monorepo-toolkit      parent:
  typescript-monorepo-toolkit       Command {
  typescript-monorepo-toolkit         commands: [Array],
  typescript-monorepo-toolkit         options: [Array],
  typescript-monorepo-toolkit         _execs: Set {},
  typescript-monorepo-toolkit         _allowUnknownOption: false,
  typescript-monorepo-toolkit         _args: [],
  typescript-monorepo-toolkit         _name: 'typescript-monorepo-toolkit',
  typescript-monorepo-toolkit         _optionValues: {},
  typescript-monorepo-toolkit         _storeOptionsAsProperties: true,
  typescript-monorepo-toolkit         _passCommandToAction: true,
  typescript-monorepo-toolkit         _actionResults: [],
  typescript-monorepo-toolkit         _helpFlags: '-h, --help',
  typescript-monorepo-toolkit         _helpDescription: 'output usage information',
  typescript-monorepo-toolkit         _helpShortFlag: '-h',
  typescript-monorepo-toolkit         _helpLongFlag: '--help',
  typescript-monorepo-toolkit         _version: '0.0.6',
  typescript-monorepo-toolkit         _versionOptionName: 'version',
  typescript-monorepo-toolkit         _events: [Object],
  typescript-monorepo-toolkit         _eventsCount: 5,
  typescript-monorepo-toolkit         tsconfigPath: 'tsconfig.json',
  typescript-monorepo-toolkit         rawArgs: [Array],
  typescript-monorepo-toolkit         args: [Array] },
  typescript-monorepo-toolkit      _description:
  typescript-monorepo-toolkit       'Inject the appropriate tsconfig references based on yarn workspaces dependency graph',
  typescript-monorepo-toolkit      _argsDescription: undefined,
  typescript-monorepo-toolkit      generateBuildAll: false,
  typescript-monorepo-toolkit      _events:
  typescript-monorepo-toolkit       [Object: null prototype] { 'option:generate-build-all': [Function] },
  typescript-monorepo-toolkit      _eventsCount: 1 } } +0ms
command exited with an error SyntaxError: Unexpected token y in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.injectRefs (/Users/kevin/.npm/_npx/12085/lib/node_modules/typescript-monorepo-toolkit/dist/commands.js:10:49)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Digging into the code a bit, I don't see any data key in my yarn workspaces info output. It's like this:

{
  "My_Project_Name/consumer-api-docs": {
    "location": "packages/consumer-api-docs",
    "workspaceDependencies": [
      "My_Project_Name/consumer-api"
    ],
    "mismatchedWorkspaceDependencies": []
  },
  "My_Project_Name/consumer-api": {
    "location": "packages/consumer-api",
    "workspaceDependencies": [
      "My_Project_Name/database-entities"
    ],
    "mismatchedWorkspaceDependencies": []
  },
  "My_Project_Name/database-entities": {
    "location": "packages/database-entities",
    "workspaceDependencies": [
      "My_Project_Name/logger"
    ],
    "mismatchedWorkspaceDependencies": []
  },
  "My_Project_Name/infrastructure": {
    "location": "packages/infrastructure",
    "workspaceDependencies": [
      "My_Project_Name/consumer-api",
      "My_Project_Name/database-entities",
      "My_Project_Name/logger",
      "My_Project_Name/migration-runner",
      "My_Project_Name/retailer-api"
    ],
    "mismatchedWorkspaceDependencies": []
  },
  "My_Project_Name/logger": {
    "location": "packages/logger",
    "workspaceDependencies": [],
    "mismatchedWorkspaceDependencies": []
  },
  "My_Project_Name/migration-runner": {
    "location": "packages/migration-runner",
    "workspaceDependencies": [
      "My_Project_Name/database-entities",
      "My_Project_Name/logger"
    ],
    "mismatchedWorkspaceDependencies": []
  },
  "My_Project_Name/retailer-api-docs": {
    "location": "packages/retailer-api-docs",
    "workspaceDependencies": [
      "My_Project_Name/retailer-api"
    ],
    "mismatchedWorkspaceDependencies": []
  },
  "My_Project_Name/retailer-api": {
    "location": "packages/retailer-api",
    "workspaceDependencies": [
      "My_Project_Name/database-entities"
    ],
    "mismatchedWorkspaceDependencies": []
  }
}

Updating the first line from:

const workspaceInfoObject = JSON.parse(JSON.parse(await helpers_1.execFile("yarn", ["workspaces", "info", "--json"], projectRoot)).data);

to

const workspaceInfoObject = JSON.parse(await helpers_1.execFile("yarn", ["workspaces", "info", "--json"], projectRoot));

seems to fix it. Should I PR this back into the project, or did I miss what the .data is for?

This is with yarn version 1.22.1.

@enzoferey
Copy link

Facing the same issue.

@Bnaya Bnaya closed this as completed in 9f4f4e1 Mar 11, 2020
Bnaya added a commit that referenced this issue Mar 11, 2020
@Bnaya
Copy link
Owner

Bnaya commented Mar 11, 2020

Thanks for the report!
A new version would be released soon, let me know if it fixes your issue!

@Bnaya Bnaya reopened this Mar 11, 2020
@Bnaya
Copy link
Owner

Bnaya commented Mar 14, 2020

@enzoferey @thekevinbrown let me know if it solves your issue

@enzoferey
Copy link

enzoferey commented Mar 15, 2020

Works for me 👍

In the meantime I have moved to a custom script that gives me a bit more flexibility as I have a monorepo mixing apps and packages (and I don't want apps to get composite: true). Still validating to see that the result of running your script and mine is only this small customization I needed 😄

@Bnaya
Copy link
Owner

Bnaya commented Mar 17, 2020

Do you think we should set composite: true only for leaf packages?
Do you know about any unwanted effect of setting composite: true to none-root packages?

@enzoferey
Copy link

enzoferey commented Mar 19, 2020

@Bnaya
Copy link
Owner

Bnaya commented Aug 28, 2020

Thanks for the feedback, if it's still a problem for you, can you open a separate feature request?

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