2017-05-22 1 views
2

ERROR in Child compilation failed: Module build failed: TypeError: Cannot read property 'newLine' of undefined at Object.getNewLineCharacter (C:...\node_modules\typescript\lib\typescript.js:9581:20) at Object.createCompilerHost (C:...\node_modules\typescript\lib\typescript.js:66675:26) at Object.ngcLoader (C:...\node_modules\@ngtools\webpack\src\loader.js:386:33): TypeError: Cannot read property 'newLine' of undefinedAngluar-cli build AOT échoue en mode de production

ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:...\src' @ ./src/main.ts 2:0-74 @ multi ./src/main.ts

npm ERR! Windows_NT 10.0.15063 npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "ng" "build" "--" "--prod" npm ERR! node v6.10.3 npm ERR! npm v3.10.10 npm ERR! code ELIFECYCLE npm ERR! [email protected] ng: ng "build" "--prod" npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] ng script 'ng "build" "--prod"'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the fol-mcdean package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! ng "build" "--prod" npm ERR! You can get information on how to open an issue for this project with: npm ERR!
npm bugs fol-mcdean npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls fol-mcdean npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request: npm ERR! C:...\npm-debug.log

J'ai un projet avec cela, en utilisant @angular 4.1.3 et @ angulaire/cli 1.1.0-rc.0 (essayé 1,04 et avec le même résultat) . Donc le projet construit bien avec ng build --aot = true mais échoue avec cette erreur en utilisant ng build --prod.

Je l'ai fait un peu de débogage \ node_modules @ ngtools \ webpack \ src \ loader.js

Et il se trouve, il se brise sur ces lignes:

function ngcLoader() { 
... 
const sourceFileName = this.resourcePath; //here is index.ts file, I'll show it later 
const plugin = this._compilation._ngToolsWebpackPluginInstance; //plugin === undefined here! 
if (plugin && plugin instanceof plugin_1.AotPlugin) { //and of course this is false 
... 
} else { 
const options = loaderUtils.getOptions(this) || {}; //and options are {} here... 
... 
const compilerHost = ts.createCompilerHost(compilerOptions); //and of cource it breaks here 
... 
} 
} 

et le fichier sur lequel il échoue est index.ts:

export * from './GJLog.component'; 

J'ai également vérifié toutes les versions de tous les paquets, le cache nettoyé, noeud .. tout réinstallées .. Mais toujours le même problème en mode AOT. Dans le même temps, il compile parfaitement avec AOT = false ...

J'ai décidé de lire ce qui est la différence entre --prod et non --prod: Et couru la commande suivante:

npm run ng build -- --aot=true --environment=prod --output-hashing=all --sourcemaps=false --extract-css=true 

Et ça a marché!

Alors, reste est la suivante:

--prod also sets the following non-flaggable settings:

1) Adds service worker if configured in .angular-cli.json.

2) Replaces process.env.NODE_ENV in modules with the production value (this is needed for some libraries, like react).

3) Runs UglifyJS on the code

Je n'ont pas des travailleurs de service et process.env.NODE_ENV n'est pas applicable non plus ... Alors est-ce UglifyJS? Vous ne savez pas quoi faire ensuite. Aucune suggestion?

+0

Voir ici: https://github.com/angular/angular-cli/issues/3985 –

+0

Non. Cela n'a pas fonctionné. J'ai essayé toutes les choses avec la réinstallation/nettoyage/réinitialisation des caches npm. Ce n'est pas le cas ... – Elastep

+0

Ensuite, je suggère d'ouvrir un problème à https://github.com/angular/angular-cli –

Répondre