curioswitch / curiostack

Full stack to help satisfy curiosity
MIT License
69 stars 17 forks source link

Base-web build failed with Cannot find module 'typescript' #444

Closed hoshir closed 5 years ago

hoshir commented 5 years ago

Recently we experiences build failures on our web client which uses base-web. I tried to look at curiostack code, but wasn't able to find any clue to fix it. Would you have any suggestion or idea on what cause this?

Curiostack version: 0.0.186

Step #3 - "curio-generated-build-all": All components are up to date.
Step #3 - "curio-generated-build-all": > Task :gcloudInstallComponents
Step #3 - "curio-generated-build-all":
Step #3 - "curio-generated-build-all": > Task :gcloudSetup
Step #3 - "curio-generated-build-all": Fetching cluster endpoint and auth data.
Step #3 - "curio-generated-build-all":
Step #3 - "curio-generated-build-all": > Task :gcloudLoginToCluster
Step #3 - "curio-generated-build-all": kubeconfig entry generated for xxxxxxxxx-cluster-jp.
Step #3 - "curio-generated-build-all":
Step #3 - "curio-generated-build-all": > Task :yarn
Step #3 - "curio-generated-build-all": [4/4] Building fresh packages...
Step #3 - "curio-generated-build-all": Done in 85.36s.
Step #3 - "curio-generated-build-all":
Step #3 - "curio-generated-build-all": > Task :yarnWarning SKIPPED
Step #3 - "curio-generated-build-all": > Task :checkNodeResolutions SKIPPED
Step #3 - "curio-generated-build-all": internal/modules/cjs/loader.js:657
Step #3 - "curio-generated-build-all": throw err;
Step #3 - "curio-generated-build-all": ^
Step #3 - "curio-generated-build-all":
Step #3 - "curio-generated-build-all": Error: Cannot find module 'typescript'
Step #3 - "curio-generated-build-all": at Function.Module._resolveFilename (internal/modules/cjs/loader.js:655:15)
Step #3 - "curio-generated-build-all": at Function.resolve (internal/modules/cjs/helpers.js:19:19)
Step #3 - "curio-generated-build-all": at Object.register (/workspace/node_modules/ts-node/dist/index.js:137:30)
Step #3 - "curio-generated-build-all": at Object.<anonymous> (/workspace/frontend/client/web/node_modules/@curiostack/base-web/build/dev/webpack/prod.js:31:20)
Step #3 - "curio-generated-build-all": at Module._compile (internal/modules/cjs/loader.js:805:30)
Step #3 - "curio-generated-build-all": at Object.Module._extensions..js (internal/modules/cjs/loader.js:816:10)
Step #3 - "curio-generated-build-all": at Module.load (internal/modules/cjs/loader.js:672:32)
Step #3 - "curio-generated-build-all": at tryModuleLoad (internal/modules/cjs/loader.js:612:12)
Step #3 - "curio-generated-build-all": at Function.Module._load (internal/modules/cjs/loader.js:604:3)
Step #3 - "curio-generated-build-all": at Module.require (internal/modules/cjs/loader.js:711:19)
Step #3 - "curio-generated-build-all": at require (internal/modules/cjs/helpers.js:14:16)
Step #3 - "curio-generated-build-all": at Object.<anonymous> (/workspace/frontend/client/web/node_modules/@curiostack/base-web/build/dev/scripts/build.js:45:16)
Step #3 - "curio-generated-build-all": at Module._compile (internal/modules/cjs/loader.js:805:30)
Step #3 - "curio-generated-build-all": at Object.Module._extensions..js (internal/modules/cjs/loader.js:816:10)
Step #3 - "curio-generated-build-all": at Module.load (internal/modules/cjs/loader.js:672:32)
Step #3 - "curio-generated-build-all": at tryModuleLoad (internal/modules/cjs/loader.js:612:12)
Step #3 - "curio-generated-build-all": error Command failed with exit code 1.
Step #3 - "curio-generated-build-all":
Step #3 - "curio-generated-build-all": > Task :frontend:client:web:buildWeb FAILED
chokoswitch commented 5 years ago

Can you try adding "typescript": "3.5.3" to your top-level package.json resolutions? We currently don't (but should) automatically add base-node-dev dependencies to the node resolutions - it's likely some package's transitive dependency on typescript is now causing dependency hell in your build.

hoshir commented 5 years ago

Thanks for the suggestion. I tired it but still got same error. The code can build in my local PC, but failed in Google Cloud Build. What I tried so far is

chokoswitch commented 5 years ago

I notice that /workspace/frontend/client/web/node_modules/@curiostack/base-web/build/dev/scripts/build.js is the location of base-web in your build. This shouldn't be the case as the version of base-web should be fixed in the top-level package.json so we'd expect /workspace/node_modules/@curiostack/base-web. Can you check that the version in the resolutions matches any in other package.json?

And if you attach redacted package.json files here, I can better understand. Just need the values for dependencies, devDependencies, and resolutions fields for any package.json files.

hoshir commented 5 years ago

Here is the resolutions in the package.json at the top level:

  "resolutions": {
    "@babel/core": "7.5.5",
    "@babel/plugin-proposal-async-generator-functions": "7.2.0",
    "@babel/plugin-proposal-class-properties": "7.5.5",
    "@babel/plugin-proposal-optional-catch-binding": "7.2.0",
    "@babel/plugin-syntax-dynamic-import": "7.2.0",
    "@babel/plugin-syntax-object-rest-spread": "7.2.0",
    "@babel/plugin-transform-react-constant-elements": "7.5.0",
    "@babel/plugin-transform-react-display-name": "7.2.0",
    "@babel/plugin-transform-react-inline-elements": "7.2.0",
    "@babel/plugin-transform-runtime": "7.5.5",
    "@babel/preset-env": "7.5.5",
    "@babel/preset-react": "7.0.0",
    "@babel/runtime": "7.5.5",
    "@babel/runtime-corejs2": "7.5.5",
    "@babel/runtime-corejs3": "7.5.5",
    "@curiostack/base-node-dev": "0.0.16",
    "@curiostack/base-web": "0.0.49",
    "@curiostack/eslint-config-base": "0.0.1",
    "@curiostack/eslint-config-web": "0.0.2",
    "@gfx/zopfli": "1.0.14",
    "@hugmanrique/react-markdown-loader": "0.0.2",
    "@storybook/addon-actions": "5.1.9",
    "@storybook/addon-backgrounds": "5.1.9",
    "@storybook/addon-links": "5.1.9",
    "@storybook/addon-options": "5.1.9",
    "@storybook/addon-viewport": "5.1.9",
    "@storybook/react": "5.1.9",
    "@types/history": "4.7.2",
    "@types/intl": "1.2.0",
    "@types/jest": "24.0.15",
    "@types/prop-types": "15.5.8",
    "@types/react": "16.8.23",
    "@types/react-dom": "16.8.5",
    "@types/react-helmet": "5.0.8",
    "@types/react-hot-loader": "4.1.0",
    "@types/react-intl": "2.3.18",
    "@types/react-loadable": "5.5.1",
    "@types/react-redux": "7.1.1",
    "@types/react-router-dom": "4.3.4",
    "@types/redux-immutable": "4.0.1",
    "@types/styled-components": "4.1.18",
    "@types/webpack-env": "1.14.0",
    "@typescript-eslint/eslint-plugin": "1.5.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-loader": "8.0.6",
    "babel-plugin-dynamic-import-node": "2.3.0",
    "babel-plugin-react-intl-auto": "1.7.2",
    "babel-plugin-styled-components": "1.10.6",
    "babel-preset-stage-0": "6.24.1",
    "brotli-webpack-plugin": "1.1.0",
    "commander": "2.20.0",
    "compression-webpack-plugin": "3.0.0",
    "connected-react-router": "6.5.2",
    "date-fns": "2.0.0-alpha.16",
    "enzyme": "3.10.0",
    "enzyme-adapter-react-16": "1.14.0",
    "enzyme-to-json": "3.3.5",
    "eslint": "5.16.0",
    "eslint-config-airbnb": "17.1.0",
    "eslint-config-airbnb-base": "13.1.0",
    "eslint-config-prettier": "4.1.0",
    "eslint-plugin-import": "2.16.0",
    "eslint-plugin-jsx-a11y": "6.2.1",
    "eslint-plugin-prettier": "3.0.1",
    "eslint-plugin-react": "7.12.4",
    "extract-react-intl-messages": "1.0.2",
    "favicons-webpack-plugin": "0.0.9",
    "file-loader": "4.1.0",
    "fontfaceobserver": "2.1.0",
    "fork-ts-checker-webpack-plugin": "1.4.3",
    "fs-extra": "8.1.0",
    "handlebars": "4.1.2",
    "history": "4.9.0",
    "html-loader": "0.5.5",
    "html-to-react": "1.3.4",
    "html-webpack-plugin": "3.2.0",
    "http-proxy-middleware": "0.19.1",
    "image-webpack-loader": "5.0.0",
    "imagemin-pngquant": "5.0.0",
    "immutable": "4.0.0-rc.12",
    "inquirer": "6.5.0",
    "intl": "1.2.5",
    "jest": "23.6.0",
    "jest-styled-components": "6.3.3",
    "loader-utils": "1.2.3",
    "mozjpeg": "6.0.1",
    "raw-loader": "3.1.0",
    "react": "16.8.6",
    "react-dom": "16.8.6",
    "react-helmet": "5.2.1",
    "react-hot-loader": "4.12.9",
    "react-intl": "2.9.0",
    "react-loadable": "5.5.0",
    "react-test-renderer": "16.8.6",
    "redux": "4.0.4",
    "redux-form-material-ui": "5.0.0-beta.3",
    "redux-form-validators": "2.7.5",
    "redux-immutable": "4.0.0",
    "reselect": "4.0.0",
    "rimraf": "2.6.3",
    "serialize-javascript": "1.7.0",
    "sharp": "0.22.1",
    "static-site-generator-webpack-plugin": "3.4.2",
    "styled-components": "4.3.2",
    "styled-components-ts": "0.0.15",
    "thread-loader": "2.1.2",
    "ts-jest": "23.10.5",
    "ts-loader": "6.0.4",
    "ts-node": "8.3.0",
    "tsconfig-paths": "3.8.0",
    "tsconfig-paths-webpack-plugin": "3.2.0",
    "tslint-config-airbnb": "5.11.1",
    "tslint-react": "4.0.0",
    "typesafe-actions": "3.0.0",
    "typescript": "3.5.3",
    "webpack": "4.37.0",
    "webpack-assets-manifest": "3.1.1",
    "webpack-cli": "3.3.6",
    "webpack-dev-server": "3.7.2",
    "webpack-sane-compiler": "3.1.1",
    "webpack-sane-compiler-reporter": "3.3.2",
    "zopfli-webpack-plugin": "0.1.0"
  },

dependencies and devDependencies in the package.json of our web client:

  "dependencies": {
    "@curiostack/base-web": "0.0.0-managed",
    "@date-io/luxon": "1.1.0",
    "@firebase/app": "0.1.8",
    "@firebase/auth": "0.3.3",
    "@material-ui/core": "4.2.0",
    "@material-ui/icons": "4.2.0",
    "@react-google-maps/api": "1.3.0",
    "autotrack": "2.4.1",
    "clean-css": "4.1.11",
    "connected-react-router": "0.0.0-managed",
    "i18n-iso-countries": "3.7.3",
    "luxon": "1.11.2",
    "material-ui-pickers": "2.2.1",
    "numeral": "2.0.6",
    "query-string": "5.1.0",
    "react-custom-scrollbars": "4.2.1",
    "react-ga": "2.5.3",
    "react-google-charts": "1.5.5",
    "react-hamburger-button": "0.0.1",
    "react-redux": "7.1.0",
    "react-resize-detector": "4.2.0",
    "react-router-dom": "5.0.1",
    "react-router-hash-link": "1.2.0",
    "redux-actions": "2.2.1",
    "redux-form": "8.1.0",
    "redux-form-material-ui": "0.0.0-managed",
    "redux-form-validators": "0.0.0-managed",
    "redux-saga": "1.0.5",
    "utility-types": "1.1.0"
  },
  "devDependencies": {
    "@types/enzyme": "3.1.8",
    "@types/fontfaceobserver": "0.0.6",
    "@types/googlemaps": "3.36.5",
    "@types/intl": "1.2.0",
    "@types/jss": "9.3.3",
    "@types/luxon": "1.11.0",
    "@types/numeral": "0.0.25",
    "@types/query-string": "5.1.0",
    "@types/react-custom-scrollbars": "4.0.3",
    "@types/react-router-hash-link": "1.2.0",
    "@types/react-test-renderer": "16.0.1",
    "@types/redux-actions": "2.2.3",
    "@types/redux-form": "7.4.16",
    "@types/react-resize-detector": "4.0.2",
    "@types/storybook__addon-actions": "3.4.2",
    "@types/storybook__react": "4.0.1",
    "@types/three": "0.89.5",
    "babel-plugin-transform-define": "1.3.0",
    "coveralls": "3.0.0",
    "cross-env": "5.1.3",
    "html-loader": "0.5.5",
    "jest-styled-components": "6.3.3",
    "markdown-loader": "3.0.0",
    "node-plop": "0.9.0",
    "plop": "1.9.1",
    "react-addons-test-utils": "15.6.2",
    "react-markdown": "3.3.4",
    "sinon": "4.2.2",
    "stylelint": "8.4.0",
    "stylelint-config-prettier": "2.0.0",
    "stylelint-config-standard": "18.0.0",
    "stylelint-config-styled-components": "0.1.1",
    "stylelint-processor-styled-components": "1.2.2"
  }
chokoswitch commented 5 years ago

Hmm - the files seem fine. I might try removing yarn.lock and regenerating it. Otherwise, it would help to add ls of frontend/node_modules and top level node_modules to see if the contents are weird (e.g., empty). Otherwise, one (usually the top level node_modules) should have typescript in it...

hoshir commented 5 years ago

I was able to solve this issue finally, by removing cloudbuild-cache-tool-node.tar.lz4 file stored in Cloud Storage created by GcloudPlugin. I thought I disabled build cache by setting org.gradle.caching = false and removing curio-generated-fetch-compressed-build-cache task in cloudbuild.yaml. However, another cache was created for node, which was broken.

By looking at code, the cache fetch is enabled only when CI environmental variable is set. This explains why builds succeeded in my local PC and building it locally even with Google Cloud Build went success.

Thanks for your support which helped me to focus more on things outside of package.json.

chokoswitch commented 5 years ago

It's interesting the node cache would cause issues as it's just the yarn cache in the home directory - probably a bug in yarn...

I also filed https://github.com/curioswitch/curiostack/issues/446 since it would make sense for that cache to not be used if caching is false, though I wonder if it would actually help debug the issue in this sort of case.

As a tip, when clearing caches, I usually search the bucket for the prefix cloudbuild-cache and delete all the files.

hoshir commented 5 years ago

To be accurate, I also deleted cloudbuild-cache-compressed.tar.lz4 as well. I thought I turned off curio-generated-fetch-compressed-build-cache task by removing it from cloudbuild.yaml, but I found I edited a wrong file. Our continuous build trigged by pull request did not use that file. Anyway, it's a good tip to delete all cloudbuild-cache-* files, thanks.

Disabling caching by gradle cache property would be of great help at least to me since I usually turn off caching when I had build errors.