Ionic 4 + Electron not works - ionic-framework

I am having problems to start a new Electron + Ionic project.
I have followed this tutorial:
https://www.9lessons.info/2018/10/ionic-electron-desktop-app.html
But when I run the project with the command:
npm run electron-serve
I get this errors on dev-tools console and the screen is white:
runtime-es2015.33b5e618b3baf74c7138.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
main-es2015.64da9645e917002baf25.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
polyfills-es2015.1b94da7ab13e05353bf7.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
/Users/myuser/ionic/Frontend/myproject/src/myproject/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/security-warnings.js:145 Electron Security Warning (Insecure Content-Security-Policy) This renderer process has either no Content Security
Policy set or a policy with "unsafe-eval" enabled. This exposes users of
this app to unnecessary security risks.
For more information and help, consult
https://electronjs.org/docs/tutorial/security.
This warning will not show up
once the app is packaged.
(anonymous) # /Users/myuser/ionic/Frontend/myproject/src/myproject/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar/renderer/security-warnings.js:145
What would be doing wrong?

Easy, Just go to src/tsconfig.json -> change the line "target" : "es2015" into "target" : "es5" then re-run "npm run electron-serve" on the terminal and the app should work.
This works for Windows 10, Ionic 5.2.7, Electron 6.0.10

For someone with the same problem:
Is not really a Capacitor bug, but a build problem in your part related to the Angular 8 build settings not being compatible with electron.
Changing the target in tsconfig.json from es2015 to es5, or add
"browserslist": [
"> 5%"
]
in the package.json
Related
Solves the problem

Related

I have an error when executing ionic serve

When I execute ionic serve, it shows the following errors:
Refused to load the image 'http://localhost:8100/favicon.ico' because
it violates the following Content Security Policy directive:
"default-src 'none'". Note that 'img-src' was not explicitly set, so
'default-src' is used as a fallback.
Failed to load resource: the server responded with a
status of 404 (Not Found)
How can I solve this?
I had the same error message.
Looking through the logs printed when doing
ionic serve
showed me a bunch of errors, all similar to this
[ng] ERROR in ./src/global.scss (./node_modules/#angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded!./node_modules/sass-loader/lib/loader.js??ref--14-3!./src/global.scss)
[ng] Module build failed (from ./node_modules/sass-loader/lib/loader.js):
[ng] Error: Cannot find module 'node-sass'
[ng] Require stack:
This lead me to get the application up and running again by
npm install node-sass --save
The compilation process is sometimes spitting out rather confusing error messages from time to time, but with a little digging one can start guessing where to start poking
I had the same issue. I was able to solve it. I fixed the routing file, I had a route that couldn't load because another route was higher order.
Ionic include default favicon icon into index.html file.
<link rel="icon" type="image/png" href="assets/icon/favicon.png" />
You can put your favicon icon into "assets/icon" and replace href above.
I had this error and it was because I had included an import I wasn't actually using. In my example, I had accidently imported Console when using console.log.
I was getting error TS2307: Cannot find module 'console'. in the VS Code terminal, but my error in Chrome was "Refused to load the image 'http://localhost:8100/favicon.ico' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.
Failed to load resource: the server responded with a status of 404 (Not Found)"
So be aware that this error is not necessarily to do with the favicon.
I had same issue but solved using below solution.
<link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico" />
I used .ico file instead of .png file and thats works for me. try once.
I get same error multiple times,this error throw when u missed any small issue like wrong image path or forget to write import statement of any module/service/component.these error will shown in terminal when u running your project.After fixing these run your project
I had the exact same problem.
I advise you to take a look at your Terminal in VSCode (or the standard terminal if you launched it by there) and look for an ERROR message.
Most likely the problem isn't the favicon.ico blabla stuff but another element of your app, something in a .ts doc for example. Via Terminal you can seek for it in a better way than Chrome, that shows you this unrelated message.
I too faced same error .In my case i have done mistake in importing file
import { IUser } from 'src/app/shared/interfaces/IUser
Changed path like below is fixed error.
import { IUser } from './shared/interfaces/IUser
Cross check your import file. it might helps
I got the same error when I downloaded a new branch of the project, I just run npm install of the lastest components
I solved by created copy favicon.png from assets/icon/favicon.png to root project folder and rename it to favicon.ico , and also put it on assets/icon/favicon.ico
and also check this answer .
https://stackoverflow.com/a/63749758/8370334
Same issue here with ionic v5 and angular v10.
You may have this error when you create some error in the variables.scss file.
I was using adding a list of global variable that will be used across the app but I forgot to add a ,.
It didn't create an error while compiling...
The code was :
$color-settings: (
'primary': (
'base': #297bfd,
) // <-- Comma is missing here
'secondary': (
'base': #297bfd,
)
}
It will display the same error, I think, it breaks somehow the way ionic compile the scss.
I had the same issue after an upgrade. I solved the problem doing:
npm rebuild node-sass
Try to change the browser, I fixed this clicking on the url resource which opened firefox and then I've been able to test the app normally on Firefox

Polymer build with custom babel plugins?

We'd like to be able to add custom functionality to polymer build and polymer serve by configuring custom babel plugins.
For example, since polymer-cli uses babel internally, we would add a babel.config.js file to our workspace/project-root, e.g.:
module.exports = function (api) {
api.cache(true);
const presets = [ ];
const plugins = [
"#babel/plugin-proposal-optional-chaining"
];
return {
presets,
plugins
};
}
...and then we could serve or build our project with support for optional-chaining, etc This would allow us to do all sorts of things by writing additional babel plugins to handle stuff like minification inside template HTML strings...
Unfortunately, this doesn't currently work. polymer-build seems to load the configuration (due to its use of babel/core?), but polymer-analyze doesn't. An error is generated in the build-optimization step performed by polymer-analyze as soon as it encounters optional-chaining syntax in our source:
error: Error: Unable to get document file:///.../somefile.js: This experimental syntax requires enabling the parser plugin:
'optionalChaining' (423:6)
at BuildAnalyzer.<anonymous> (/usr/local/share/.config/yarn/global/node_modules/polymer-build/lib/analyzer.js:342:23)
at Generator.next (<anonymous>)
at fulfilled (/usr/local/share/.config/yarn/global/node_modules/polymer-build/lib/analyzer.js:17:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
polymer serve also generates an error:
Error { SyntaxError: This experimental syntax requires enabling the parser plugin: 'optionalChaining' (423:6)
at Parser.raise (/usr/local/share/.config/yarn/global/node_modules/babylon/lib/index.js:776:15)
at Parser.expectPlugin (/usr/local/share/.config/yarn/global/node_modules/babylon/lib/index.js:2084:18)
...
pos: 13056, loc: Position { line: 423, column: 6 },
missingPlugin: [ 'optionalChaining' ] }
In both cases, I've confirmed that the babel.config.js file is being loaded. But babel is included by several different packages used in polymer-cli, so my suspicion is that in some of them, babel is being used without (babel/core having loaded) configuration info.
Can anyone involved with the polymer project confirm whether I'm correct in identifying the main issue? I'm looking into the possibility of contributing a fix/enhancement if the scope isn't too large.
Thanks.
I think for this you need to write your own custom build. Polymer-cli will provide its tool also for this. Have a look at this example:
https://github.com/PolymerElements/generator-polymer-init-custom-build
For us, this issue was preventing us from using modern JS language features (like optional chaining and the nullish coalescing operator) which have wide support in modern browsers.
The only solution we could come up with was forking the Polymer tools monorepo and adding in support for the appropriate Babel plugins ourselves.
The file in question is /packages/build/src/js-transform.ts. Both serve and build use this file for Babel transforms. We switched to using Rollup for our build process, but we still needed a development server and couldn't get any others to work, so we forked the repo and built our own version of the standalone polyserve package. Would love to some day switch to Modern Web's #web/dev-server.

making sure the polymer build process doesn't mess with a dependency of my element

I have built a custom element/web component to load and display Unity generated WebGL content. The web component imports the UnityLoader.js module - and works fine when used within an app served with 'polymer serve'.
However, when I build an app that uses my web component via the Polymer-CLI build process, no errors are given, but when I access a page using my component I always end up with an error from within UnityLoader.js:
"ReferenceError: BabelHelpers is not defined"
If I create the element directly within my app (in other words it is no longer managed by bower) then I can exclude the minification and compilation steps within the build section of my application's polymer.json file and the built version of the app works fine.
"builds": [
{
"preset": "es5-bundled",
"js": {
"compile": {"exclude": ["content/**/*","UnityLoader.js"]},
"minify": {"exclude": ["content/**/*","UnityLoader.js"]}
},
"html": {
"minify": {"exclude": ["content/**/*"]}
}
}
]
I've looked at my application's polymer.json file and I can see that the extraDependecies node contains some dependencies that other web components have placed there:
"extraDependencies": [
"bower_components/webcomponentsjs/*.js",
"!bower_components/webcomponentsjs/gulpfile.js",
"manifest.json",
"bower_components/plastic-image/intersection-observer.js",
"bower_components/ua-parser-js/dist/ua-parser.min.js"
],
I have UnityLoader.js within the extraDependencies of the element's polymer.json but that isn't getting cascaded up to an application that imports/consumes the element - which I guess must be possible as plastic-image and ua-parser-js have done it (I've looked at their bower_components folders and nothing seems obvious - other than the latter is installed as a dependency of the former).
Any ideas on how I can make sure that the UnityLoader.js that my web component uses is not compiled or minified during the build process of an application that consumes it?
I was having a similar issue with firebase-auth.js when making an ES5 build using polymer-cli 1.7.0. There might be a problem when compiling/minifying specific files. I had to roll back to 1.6.0 using npm install -g polymer-cli#1.6.0 to fix the problem.

How can I fix tests in Ember testem with errors such as 'could not load', 'failed', 'could not find module' or 'died'?

I managed to get a couple of EAK/grunt based Ember apps upgraded to 1.11 with HTMLBars, and then got them migrated to Ember CLI/Brocolli. The unit tests were setup for karma test runner so I'm looking at how to get those running in the CLI projects now, but I didn't write the tests and really have no experience with unit testing javascript modules.
Searching around the iNet, I can see that others have also used karma becasue of its coverage output and are trying to get it to work with Ember CLI, but that Ember Core isn't supporting it, though they say anyone should be able to get it set up with a custom addon. I'm also trying to use the 'testem' runner to see what sticks with that.
The Ember site does have an 'automating tests with runners' page for v1.10, with sections on 'testem' and 'karma', but it doesn't appear for v1.11 so I can't tell from that site what is or isn't relevant. But it seems like I should be able to work out a solution for the karma test runner, so I added the old devDependencies to the project package.json:
"karma": "^0.12.31",
"karma-chai": "~0.1.0",
"karma-chrome-launcher": "~0.1.2",
"karma-coverage": "~0.2.1",
"karma-firefox-launcher": "~0.1.3",
"karma-junit-reporter": "~0.2.1",
"karma-mocha": "~0.1.3",
"karma-phantomjs-launcher": "~0.1.2",
"karma-sinon-chai": "~0.1.5"
I also dropped the old 'karma.conf.js' (along with a few other karma confs) in the project and updated the paths inside (from 'vendor' to 'bower_components'). I did find a 'ember-cli-karma' node mode and installed it, but it seems to just have a 'package.json'. It has no docs and seems like just a stubbed out starter project with no implementation. I also installed 'karma', 'karma-cli' and 'testem' node modules.
The testem docs say to add you src and test files to 'testem.json', but with out examples I don't know what that means; a list of every src and test file? With what path; relative, absolute? Forward slashes, backslashes? preceded with / or ./ or ../? I just left them out because I think the system just finds the src and tests by convention.
When I run 'karma init' I get:
readline.js:529
this.line = this.line.slice(this.cursor);
^
TypeError: Cannot read property 'slice' of undefined
When I run 'testem' I get:
TEST'EM 'SCRIPTS!
Open the URL below in a browser to connect.
http://localhost:7357/aN;0faN;NaNf
...then the project's '../tests/index.html' loads in a browser, but is not able to 'find' any of the asset files (css, js) so nothing executes or renders correctly. I just see template expressions ({{content-for 'head'}}, etc).
When I run 'ember test' I get:
Building...BuildingBuilding.Building..Building...Built project successfully.
1..0
# tests 0
# pass 0
# fail 0
# ok
No tests were run, please check whether any errors occurred in the page (ember test --server) and ensure that you have a test launcher (e.g. PhantomJS) enabled.
When I run 'ember test --server' I get:
The test index.html loaded in a browser with a test report. When I uncheck 'hide passed tests' the report indicates '29 passed, 28 failed'. It has 11 sections where a particular test may have 3 problems such as 'could not load', 'failed', 'could not find module', 'attempting to register an unknown factory' or 'died'.
With this, I'm obviously running testem and not karma, so may as well work on getting testem working and figure out karma later. If there were more examples and migration troubleshooting docs I might have a systematic way to work through some of these problems.
I ran into "No tests were run,..." problem recently after a node upgrade. I fixed it with a:
npm install -g phantomjs
This provides some additional options as well:
https://github.com/ember-cli/ember-cli/issues/3969
I had the Cannot read property 'slice' of undefined error on MS Windows, running via MSys2. I have solved it by using karma init from an ordinary cmd prompt.

Confirmation was required to visit untrusted URL

Hi Im using eclipse-jee-galileo-win32 for development. I tried to install GWT using eclipse plugin for following link gwt - http://dl.google.com/eclipse/plugin/3.5. But it will displayed following error. How can i solve this problem.
[WARN] Confirmation was required to visit untrusted URL: 'http://gwt.google.com/missing-plugin
[WARN] reason: http://gwt.google.com/missing-plugin is not in the whitelist
whitelist:
blacklist:
To fix: add regex matching URL to -whitelist command line argument
Example: -whitelist=" ^http[:][/][/]gwt[.]google[.]com"
Example: -whitelist=" ^http[:][/][/]gwt[.]google[.]com"
To reject automatically: add regex matching URL to -blacklist command line argument
Example: -blacklist=" ^http[:][/][/]gwt[.]google[.]com"
Example: -blacklist=" ^http[:][/][/]gwt[.]google[.]com"
Unknown module requested 'missingplugin'; all active GWT modules must be specified in the command line arguments
This is caused due to your browser not having the necessary plugin to talk to GWT/Eclipse. Visit that page (http://gwt.google.com/missing-plugin) in your browser, install the plugin, restart the browser, retry the (local?) GWT page.