embroider-build / embroider

Compiling Ember apps into spec-compliant, modern Javascript.
MIT License
339 stars 137 forks source link

Production build errors with "needed by index.html: Cannot read property '0' of undefined" #668

Open scottmessinger opened 3 years ago

scottmessinger commented 3 years ago

Hi! I'm trying to build in production (ember build --environment=production) and am getting this error:

Build Error (PackagerRunner)

TypeError: needed by index.html: Cannot read property '0' of undefined
Here's my package.json ```json { "devDependencies": { "@ember/optional-features": "^2.0.0", "@ember/render-modifiers": "^1.0.2", "@embroider/compat": "^0.35.1", "@embroider/core": "^0.35.1", "@embroider/webpack": "^0.35.1", "@glimmer/component": "^1.0.1", "@glimmer/tracking": "^1.0.1", "@types/ember": "^3.16.1", "@types/ember-qunit": "^3.4.12", "@types/ember-resolver": "^5.0.10", "@types/ember__test-helpers": "^1.7.3", "@types/qunit": "^2.9.5", "@typescript-eslint/parser": "^4.4.0", "babel-eslint": "^8.0.0", "broccoli-asset-rev": "^3.0.0", "ember-animated": "^0.10.1", "ember-auto-import": "^1.6.0", "ember-cli": "~3.21.2", "ember-cli-app-version": "^3.2.0", "ember-cli-babel": "^7.22.1", "ember-cli-bundle-analyzer": "^0.2.1", "ember-cli-dependency-checker": "^3.2.0", "ember-cli-deploy": "^1.0.2", "ember-cli-deploy-build": "^2.0.0", "ember-cli-deploy-display-revisions": "^2.1.2", "ember-cli-deploy-revision-data": "commoncurriculum/ember-cli-deploy-revision-data", "ember-cli-deploy-s3": "^3.0.0", "ember-cli-deploy-s3-prember": "github:commoncurriculum/ember-cli-deploy-s3-prember#b7af484bc99938c3b2ce0a3666e1060a19cea038", "ember-cli-fastboot": "^3.0.0-beta.2", "ember-cli-htmlbars": "^5.3.1", "ember-cli-inject-live-reload": "^2.0.2", "ember-cli-segment": "^4.1.0", "ember-cli-sri": "^2.1.1", "ember-cli-string-helpers": "^5.0.0", "ember-cli-terser": "^4.0.0", "ember-cli-typescript": "^4.0.0", "ember-cli-typescript-blueprints": "^3.0.0", "ember-composable-helpers": "^4.3.0", "ember-could-get-used-to-this": "^1.0.1", "ember-css-modules": "^1.3.2", "ember-decorators": "^6.1.1", "ember-export-application-global": "^2.0.1", "ember-fetch": "^8.0.2", "ember-load-initializers": "^2.1.1", "ember-math-helpers": "^2.15.0", "ember-maybe-import-regenerator": "^0.1.6", "ember-modifier": "^2.1.1", "ember-page-title": "^6.0.1", "ember-qunit": "^4.6.0", "ember-resolver": "^8.0.2", "ember-source": "~3.23.1", "ember-template-lint": "^2.13.0", "ember-template-lint-plugin-prettier": "^2.0.0", "ember-truth-helpers": "^3.0.0", "ember-welcome-page": "^4.0.0", "eslint": "^7.8.0", "eslint-plugin-ember": "^8.13.0", "eslint-plugin-node": "^11.1.0", "loader.js": "^4.7.0", "lodash-es": "^4.17.15", "npm-run-all": "^4.1.5", "postcss": "^7.0.35", "postcss-import": "^12.0.1", "postcss-nested": "^4.2.3", "prember": "github:simonihmig/prember#embroider", "prember-middleware": "^0.1.0", "prettier": "^2.1.2", "qunit-dom": "^1.4.0", "tailwindcss": "^1.8.12", "tracked-built-ins": "^1.0.2", "typescript": "^4.0.3" }, "engines": { "node": "10.* || >= 12" }, "ember": { "edition": "octane" }, "dependencies": { "@embroider/router": "^0.35.1", "@sentry/browser": "^5.29.1", "@types/lodash-es": "^4.17.3", "@types/prismic-dom": "^2.1.1", "macro-decorators": "^0.1.2", "prismic-dom": "^2.2.4", "webpack-bundle-analyzer": "^3.9.0" }, } ```
Here's the error ```sh ================================================================================= ERROR Summary: - broccoliBuilderErrorStack: TypeError: needed by index.html: Cannot read property '0' of undefined at getPropertyDescriptor (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/utils/names.js:63:24) at getPropertyFingerprint (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/6-restructBlock.js:72:20) at List. (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/6-restructBlock.js:217:27) at List.eachRight (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/common/List.js:181:12) at Object.processRule (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/6-restructBlock.js:215:18) at Object.enter (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/6-restructBlock.js:297:25) at Object. (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:11:16) at walkNode (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:165:34) at List.walkReducer (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:189:61) at List.reduceRight (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/common/List.js:229:18) at Object.StyleSheet (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:104:31) at walkNode (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:177:41) at walk (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:236:9) at restructBlock (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/6-restructBlock.js:274:5) at module.exports (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/index.js:27:5) at compressChunk (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/compress.js:77:9) - code: [undefined] - codeFrame: needed by index.html: Cannot read property '0' of undefined - errorMessage: needed by index.html: Cannot read property '0' of undefined at PackagerRunner (@embroider/webpack) -~- created here: -~- at new Plugin (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/@embroider/core/node_modules/broccoli-plugin/dist/index.js:45:33) at new PackagerRunner (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/@embroider/core/src/to-broccoli-plugin.js:10:13) at Object.defaultPipeline (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/@embroider/compat/src/default-pipeline.js:43:12) at module.exports (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/ember-cli-build.js:106:52) at Builder.readBuildFile (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/ember-cli/lib/models/builder.js:49:14) at Builder.setupBroccoliBuilder (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/ember-cli/lib/models/builder.js:63:22) at new Builder (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/ember-cli/lib/models/builder.js:29:10) at BuildTask.run (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/ember-cli/lib/tasks/build.js:13:19) at Promise.resolve.then (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/ember-cli/lib/models/command.js:238:24) at process._tickCallback (internal/process/next_tick.js:68:7) -~- (end) -~- - errorType: Build Error - location: - column: [undefined] - file: [undefined] - line: [undefined] - treeDir: [undefined] - message: needed by index.html: Cannot read property '0' of undefined at PackagerRunner (@embroider/webpack) -~- created here: -~- at new Plugin (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/@embroider/core/node_modules/broccoli-plugin/dist/index.js:45:33) at new PackagerRunner (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/@embroider/core/src/to-broccoli-plugin.js:10:13) at Object.defaultPipeline (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/@embroider/compat/src/default-pipeline.js:43:12) at module.exports (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/ember-cli-build.js:106:52) at Builder.readBuildFile (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/ember-cli/lib/models/builder.js:49:14) at Builder.setupBroccoliBuilder (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/ember-cli/lib/models/builder.js:63:22) at new Builder (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/ember-cli/lib/models/builder.js:29:10) at BuildTask.run (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/ember-cli/lib/tasks/build.js:13:19) at Promise.resolve.then (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/ember-cli/lib/models/command.js:238:24) at process._tickCallback (internal/process/next_tick.js:68:7) -~- (end) -~- - name: Error - nodeAnnotation: @embroider/webpack - nodeName: PackagerRunner - originalErrorMessage: needed by index.html: Cannot read property '0' of undefined - stack: TypeError: needed by index.html: Cannot read property '0' of undefined at getPropertyDescriptor (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/utils/names.js:63:24) at getPropertyFingerprint (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/6-restructBlock.js:72:20) at List. (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/6-restructBlock.js:217:27) at List.eachRight (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/common/List.js:181:12) at Object.processRule (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/6-restructBlock.js:215:18) at Object.enter (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/6-restructBlock.js:297:25) at Object. (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:11:16) at walkNode (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:165:34) at List.walkReducer (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:189:61) at List.reduceRight (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/common/List.js:229:18) at Object.StyleSheet (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:104:31) at walkNode (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:177:41) at walk (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/css-tree/lib/walker/create.js:236:9) at restructBlock (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/6-restructBlock.js:274:5) at module.exports (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/restructure/index.js:27:5) at compressChunk (/Users/scottmessinger/code/commoncurriculum/v4/app/static-frontend/node_modules/csso/lib/compress.js:77:9) ================================================================================= ```

My guess: it's related to minifying css

Based on the stack trace, it appears be related to CSS processing. I wasn't getting this error on 0.27.0 and I'm also not getting it when I run ember serve -- it's only when I run it in with the production flag. This makes me think it might be caused by the change to minifying CSS in production environments.

22a commented 3 years ago

We were running into this issue with an internal addon too. Having played around with our config and dug into the trace it looks like getPropertyDescriptor and Object.processRule inside the webpack bundle are of most interest and point to a particular css rule not being parseable.

From your package.json it looks like you too are using postcss and tailwind so I suspect your production build issue may be related to postcss at-rules not being understood. @tailwind and @apply, if not unravelled by postcss by the time webpack wants to produce a bundle, may be what's causing the issue - in our case (as we're still working on reaching postcss compatibility), removing all @apply invocations fixed the production build error.


As an aside, the top level error for this is a bit opaque (TypeError: needed by index.html: Cannot read property '0' of undefined) so perhaps it could be improved with a bit more context on what part of the webpack bundle stage is falling over.