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 read property 'resolvedModules' of undefined when running tscc with Yarn 2 #464

Open
Ririshi opened this issue Feb 5, 2021 · 3 comments
Labels

Comments

@Ririshi
Copy link

Ririshi commented Feb 5, 2021

When trying to run tscc on my Node project, I am getting the following error:

TypeError: Cannot read property 'resolvedModules' of undefined
    at TypescriptDependencyGraph.walk (<project_folder>\.yarn\cache\@tscc-tscc-npm-0.6.3-0d17947750-0211229831.zip\node_modules\@tscc\tscc\dist\graph\TypescriptDependencyGraph.js:81:16)
    at TypescriptDependencyGraph.walk (<project_folder>\.yarn\cache\@tscc-tscc-npm-0.6.3-0d17947750-0211229831.zip\node_modules\@tscc\tscc\dist\graph\TypescriptDependencyGraph.js:83:22)
    at TypescriptDependencyGraph.walk (<project_folder>\.yarn\cache\@tscc-tscc-npm-0.6.3-0d17947750-0211229831.zip\node_modules\@tscc\tscc\dist\graph\TypescriptDependencyGraph.js:83:22)
    at TypescriptDependencyGraph.addRootFile (<project_folder>\.yarn\cache\@tscc-tscc-npm-0.6.3-0d17947750-0211229831.zip\node_modules\@tscc\tscc\dist\graph\TypescriptDependencyGraph.js:112:14)
    at <project_folder>\.yarn\cache\@tscc-tscc-npm-0.6.3-0d17947750-0211229831.zip\node_modules\@tscc\tscc\dist\tscc.js:45:72
    at Array.forEach (<anonymous>)
    at Object.tscc [as default] (<project_folder>\.yarn\cache\@tscc-tscc-npm-0.6.3-0d17947750-0211229831.zip\node_modules\@tscc\tscc\dist\tscc.js:45:38)
    at main (<project_folder>\.yarn\cache\@tscc-tscc-npm-0.6.3-0d17947750-0211229831.zip\node_modules\@tscc\tscc\dist\main.js:27:25)
    at Object.<anonymous> (<project_folder>\.yarn\cache\@tscc-tscc-npm-0.6.3-0d17947750-0211229831.zip\node_modules\@tscc\tscc\dist\main.js:139:5)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)

I've attached some info I think is relevant. I am using Yarn 2 (as you can probably see from the error trace). I am calling tscc using the yarn build command, defined in package.json below.

tsconfig.json:

{
  "compilerOptions": {
    "importHelpers": true,
    "lib": ["ES2020"],
    "module": "CommonJS",
    "moduleResolution": "node",
    "noImplicitAny": false,
    "preserveConstEnums": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "target": "ES6",
    "typeRoots": ["./node_modules/@types", "./src/typings"]
  },
  "include": ["src/**/*"]
}

tscc.spec.json:

{
  "modules": {
    "out": "src/main.ts"
  },
  "external": {
    "ajv": "AJV",
    "dayjs": "DayJS",
    "deepmerge": "DeepMerge",
    "discord.js": "DiscordJS",
    "glob": "Glob",
    "type-fest": "TypeFest"
  },
  "prefix": "dist/"
}

Relevant info in package.json:

{
  "scripts": {
    "build": "tscc --spec tscc.spec.json",
  },
  "dependencies": {
    "ajv": "^7.0.4",
    "dayjs": "^1.10.3",
    "deepmerge": "^4.2.2",
    "discord.js": "^12.5.1",
    "glob": "^7.1.6",
    "type-fest": "^0.20.2"
  },
  "devDependencies": {
    "@tscc/tscc": "^0.6.3",
    "@types/glob": "^7.1.3",
    "@types/node": "^14.14.16",
    "@typescript-eslint/eslint-plugin": "^4.11.1",
    "@typescript-eslint/parser": "^4.11.1",
    "eslint": "^7.16.0",
    "eslint-config-prettier": "^7.1.0",
    "eslint-plugin-prettier": "^3.3.0",
    "node-schedule": "^1.3.2",
    "nodemon": "^2.0.6",
    "prettier": "^2.2.1",
    "ts-node": "^9.1.1",
    "tslib": "^2.1.0",
    "typescript": "^4.0",
    "typescript-json-schema": "^0.48.0"
  }
}
@theseanl
Copy link
Owner

theseanl commented Feb 9, 2021

This is definitely a Yarn 2 issue. Could you change the issue title to reflect this?

Also, do you have any knowledge on internal working of yarn 2, such as, about what it does to JS execution environment and typescript package to make it work with its new module structures?
I've researched about Yarn 2 a bit, but I couldn't find a central source of truth. I even sympathize with MS employee's conservative stance, its .pnp.js file format seems like a mess (I just created a package with your provided info, and did yarn install).

I'd appreciate if someone having experiences with yarn 2, .pnp.js could point out what needs to be done in Typescript API consumer's side. Currently the same API calls to Typescript compiler that works fine in usual circumstances is failing with yarn 2. If they are doing custom modification to installed typescript package contents and node execution environment, I reckon it's their responsibility to make it transparent to any users of TS.

@Ririshi Ririshi changed the title "Cannot read property 'resolvedModules' of undefined" when compiling with tscc Cannot read property 'resolvedModules' of undefined when running tscc with Yarn 2 Feb 10, 2021
@Ririshi
Copy link
Author

Ririshi commented Feb 10, 2021

Thanks for confirming that it is indeed Yarn 2.

It seems like Yarn 2 packs up the entire node_modules environment into zip files to reduce file size and the number of files. There is still a way to work with the "old" node_modules structure, using pnpify, but that is more of a short-term patch than a long-term solution.

I'd love to be able to use tscc with Yarn 2, but I also only just switched to try it out on a single project, so I don't really know of how much help I can be.

@merceyz
Copy link

merceyz commented Apr 26, 2021

This is definitely a Yarn 2 issue.

If anyone could provide a repo that can be cloned and run to test this I can look into it, if we're breaking something in TypeScript that definitely needs to be fixed on our side.

There is still a way to work with the "old" node_modules structure, using pnpify,

@Ririshi I highly suggest giving https://yarnpkg.com/getting-started/migration#step-by-step a read, it shows you can get the old node_modules layout.

yarn config set nodeLinker node-modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants