`ng build --prod` завершается с ошибкой`ERROR в TypeError: Невозможно прочитать свойство 'version' из null`

Я не могу успешно заставить мой проект строить с --prod флаг [в противном случае он работает нормально]. Я могу временно добавить maxMetadata && в операторе if, где возникает ошибка, для проверки нуля и прохождения этой точки (строка 66 metadata_reader.js), а затем я получаю список "реальных" проблем, связанных с производственным дистрибутивом; но я хотел бы получить некоторое представление о том, почему это происходит в первую очередь, и посмотреть, есть ли постоянное исправление. Мне удалось найти похожие проблемы вокруг, и я попробовал многое из того, что пробовали другие люди, но, похоже, это не совсем та же проблема, и я до сих пор не нашел решения.

Версии:

Angular CLI: 1.6.5
Node: 8.9.4
OS: win32 x64
Angular: 5.2.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.5
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.5
@schematics/angular: 0.1.17
typescript: 2.7.1
webpack: 3.10.0

Полная трассировка стека:

ERROR in TypeError: Cannot read property 'version' of null
    at readMetadataFile (C:\git\screenings-plus\node_modules\@angular\compiler-cli\src\transformers\metadata_reader.js:66:29)
    at Object.readMetadata (C:\git\screenings-plus\node_modules\@angular\compiler-cli\src\transformers\metadata_reader.js:35:25)
    at TsCompilerAotCompilerTypeCheckHostAdapter.getMetadataFor (C:\git\screenings-plus\node_modules\@angular\compiler-cli\src\transformers\compiler_host.js:425:34)
    at StaticSymbolResolver.getModuleMetadata (C:\git\screenings-plus\node_modules\@angular\compiler\bundles\compiler.umd.js:29726:62)
    at StaticSymbolResolver.hasDecorators (C:\git\screenings-plus\node_modules\@angular\compiler\bundles\compiler.umd.js:29426:46)
    at analyzeFile (C:\git\screenings-plus\node_modules\@angular\compiler\bundles\compiler.umd.js:31299:63)
    at AotCompiler._analyzeFile (C:\git\screenings-plus\node_modules\@angular\compiler\bundles\compiler.umd.js:30509:17)
    at AotCompiler.findGeneratedFileNames (C:\git\screenings-plus\node_modules\@angular\compiler\bundles\compiler.umd.js:30525:42)
    at Object.findGeneratedFileNames (C:\git\screenings-plus\node_modules\@angular\compiler-cli\src\transformers\program.js:397:82)
    at TsCompilerAotCompilerTypeCheckHostAdapter.getSourceFile (C:\git\screenings-plus\node_modules\@angular\compiler-cli\src\transformers\compiler_host.js:337:55)
    at findSourceFile (C:\git\screenings-plus\node_modules\typescript\lib\typescript.js:74915:29)
    at args (C:\git\screenings-plus\node_modules\typescript\lib\typescript.js:74852:85)
    at getSourceFileFromReferenceWorker (C:\git\screenings-plus\node_modules\typescript\lib\typescript.js:74825:34)
    at processSourceFile (C:\git\screenings-plus\node_modules\typescript\lib\typescript.js:74852:13)
    at processRootFile (C:\git\screenings-plus\node_modules\typescript\lib\typescript.js:74706:13)
    at C:\git\screenings-plus\node_modules\typescript\lib\typescript.js:73855:60

1 ответ

Решение

Чтобы решить проблему, я разместил console.log(maxMetadata.version); в строке 66 файла metadata_reader.js и смог найти источник проблемы, который оказался файлом метаданных [*.metadata.json] в моем проекте. Это было [null] который должен быть [] для всех текущих версий Angular. Как только это было изменено, я смог получить нормальный ng build --prod построение показаний.

Другие вопросы по тегам