-
Notifications
You must be signed in to change notification settings - Fork 12k
ng build --prod | ERROR in Expected 'styles' to be an array of strings. #5989
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
Comments
Also, this seems to work fine: Any suggestions or help is appreciated. |
can you share a sample project to reproduce? |
also make you your @angular/compiler-cli version matches the version of angular you are using |
@deebloo I'm pretty sure my angular version is on 4.0.2 which matches my @angular/compiler-cli version (also 4.0.2). |
Maybe there is something wrong in my angular-cli.json file. Have a look and let me know if you see anything strange:
|
The error makes it sound like there is something wrong in the main.ts file, so here's that too:
|
Also getting this same exact error. There are a lot of solutions on the Webpack git, but we don't have access to the Webpack config to make those fixes. |
Yes, the fixes you referenced would require us to run A solution with the cli would be ideal. |
@kblestarge run this command if you have a tsconfig-aot.json
|
I started this issue because while it is related I don't believe it is the same thing |
@xtianus79, my project doesn't have a tsconfig-aot.json. Should I still run that command? |
@xtianus79 I ran it, but it gave me the following error: Do I need to create a tsconfig-aot.json file? |
@kblestarge yes you need the file at your root
|
@xtianus79, I added the file and ran Here's the error:
|
@kblestarge hahaha... so it is the same bug** well i don't know if this is the compiler-cli's fault or angular-cli.... |
I opened an issue here that is in the actual angular repo... |
@kblestarge can you please provide a minimal reproduction of this issue? |
I have the same issue. If it helps I have a minimal repro here https://github.com/scascarini/repo5989 The only changes from a raw ng new project are to add 'requires' to the template and styles in app.component.ts and to copy across my custom tsconfig.app.json settings from my original project. |
@scascarini require ('somestring') is not a string, you need to pass a string not a require |
@Toxicable It works (ie builds and runs) in other than the AoT build. http://stackoverflow.com/questions/37244821/angular-2-template-syntax |
@scascarini JIT does not have type safety, AOT does, therefore just because it works in JIT doesn't mean it will in AOT |
@Toxicable I think the underlying issue is that 'require' works in JIT (ie it's returning the template as a string) and it doesn't work in AoT (ie it returns null/undefined). Question is - should it work ? |
@scascarini no, becasue unless my understanding is incorrect, since the AOT compiler does not execute your code then it cannot call the require function and retrieve the template, since it cannot retrieve the template it cannot compile your code |
I had hopes this would work. But same issue (works OK ng build but not ng build --prod)
|
@scascarini why aren't you just using a path? |
@Toxicable I need to be able to build and deploy my components as node modules - paths don't work (or at least didn't last time I tried on @angular/[email protected]) |
@kblestarge ok. was just looking at your package.json and it said you compiler cli version is |
@Toxicable if JIT doesn't have type safety and AOT does than that is a huge problem... A user should expect that if it is running it in JIT than things should be running in AOT. Also, JIT may not have type safety but running your application tied to an tsconfig gives your application type saftey... So again, a user would expect a similiar result in method of deployment. This is certainly a bug or at the least not a well thought out flow. |
@xtianus79 I think I misworded that slightly, the AOT compiler has type safety since it's run before transpilstion, the JIT compiler does not since it's run after transpilstion and this is never going to change, you cannot run the JitCompiler on untranspiled code |
@Toxicable ahhhh ok. I get what you're saying now. So AOT using typescript is causing this issue |
@deebloo my package.json may say that in the devDependencies, but in the normal dependencies, it looks like it's the updated version: |
@xtianus79 or @Toxicable, any suggestions for workarounds? This is how I'm building my deliverable project in the meantime: |
@kblestarge the work around is to do it correctly, ie, use an actual path not a require |
@Toxicable can you give me an example? |
Are you suggesting that I change component meta data from this:
to this:
? |
yes |
@Toxicable, thank you. This solved my problem. Now I just have to change all of my private variables that are referenced in external templates to public variables. I wish this problem was mentioned in the Angular changelog. Here's the issue I'm referencing. |
Will this work for SASS files too? |
@select yes |
Unfortunately it doesn't work if I'm building and deploying the component as a node module. So it looks like I shall either have to embed the templates directly (which is ugly) or copy the templates in as a pre-build step (which is what I'd hoped require or import would stop me having to do - and which works fine in non-AoT builds). |
This popped up for me right after I'd added a new stylesheet to the styles array inside of the .angular-cli.json file, and the error message seemed to imply there was a problem with the styles array inside that file. The issue though, was inside a component referencing the same stylesheet at a different path. The styles array in the component had to be corrected to match the reference that was newly added to .angular.cli.json and then the error resolved. |
I'm having this issue after migrating to Angular 4 from 2. I don't include any of my styles by require() and nor do I reference any of the styles in my angular-cli styles array directly in any of my components as @sqlsolver suggested. I've globally commented out all of my styles and styleUrls on my components as a test and I still get the same error. Is it possible that the error is coming from a 3rd party library I am using? |
@timdk it is possible, yes |
As an update to anyone else having this issue: I updated all of my packages to the latest version and it gave me some new warnings that it previously didn't warn about. Once I fixed those the build succeeds. I still had one component that used a private member in its template and in my router testing stubs files I declared a module before its components. One of those components doesn't declare any styles (router outlet stub) so maybe the error was coming from that. |
Hi, I am having this issue while ng build --prod. it works fine ng build but give issue in ng build --prod ERROR in Expected 'styles' to be an array of strings. ERROR in ./src/main.ts |
@YadJosan, make sure you are not using |
@kblestarge Thanks . can you please let me know how we can minify js in cli |
@YadJosan, I'm pretty sure the cli does the minifying for us with Webpack upon building the project. You shouldn't have to manually configure anything... |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Versions.
@angular/cli: 1.0.0
node: 6.9.3
os: darwin x64
@angular/animations: 4.0.2
@angular/common: 4.0.2
@angular/compiler: 4.0.2
@angular/compiler-cli: 4.0.2
@angular/core: 4.0.2
@angular/forms: 4.0.2
@angular/http: 4.0.2
@angular/material: 2.0.0-beta.3
@angular/platform-browser: 4.0.2
@angular/platform-browser-dynamic: 4.0.2
@angular/platform-server: 4.0.2
@angular/router: 4.0.2
@angular/cli: 1.0.0
Repro steps.
Run this:
ng build --prod
package.json:
The log given by the failure.
Here is the error that came from the
ng build --prod
:Desired functionality.
This should successfully create the production build without any fatal errors.
Mention any other details that might be useful.
The text was updated successfully, but these errors were encountered: