1

I was using angular 6. I was building my project with this cli command:

ng build --prod --base-href=

Then, I was opening dist/index.html directly, without a server, and in those happy days in this way I could use my project offline.

Recently I have updated angular to 8. Now, I build with the same command. However, now I get CORS error:

Access to script at 'file:///D:/...../polyfills-es2015.707fe33a73ba6b994c2b.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

What has changed? How could I use my project offline just like before?

Edit:

Now I am able to answer

"What has changed?"

Before, in index.html, type for script was "text/javascript". But now I see "module".

Before:

<script type="text/javascript" src="main.90ef8874f90877154126.bundle.js">

Now:

<script src="main-es2015.057f1c108bdef8198685.js" type="module">

When I convert module to text/javascript, it works.

But now I don't know what type="module" is for, why angular, or cli, started to put "module", why Chrome does not let it, and how I can force angular to not put "module" but simply "text/javascript".

Mert Mertce
  • 1,049
  • 7
  • 34
  • Is there any reason why you're not using ng serve? I don't see a reason why you wouldn't use it, as it boots a very basic local server, which means that it's offline, ans allows you to use http protocol, not file, which is a lot different. – Supamiu May 06 '20 at 11:28
  • Simple reason. I distribute this to users. They don't necessarily have "ng serve". They just use the app offline. No more stories. – Mert Mertce May 06 '20 at 11:30
  • 1
    Bit confused about why you would distribute html page and its javascript files to the user. What kind of users are they; end-users, qa, co-workers? Isn't it better to deploy the website on a lightweight server somewhere and just give them a link? – madteapot May 06 '20 at 13:23

1 Answers1

1

I have never tried to do this thing (because I never had the need) but an idea could be to transform your app into a desktop app with Electron. There are software like Hyper (and it seems that VS Code too) which are actually Javascript/html/css software which however are designed to run on a desktop and not on a web browser.

Reference: https://www.electronjs.org/

I think your need is just that.

Sandman
  • 1,480
  • 7
  • 23
  • I have used cordova for mobile apps but hadn't tried for desktop. Now I had a look. This does not answer the question but it is useful, thank you. – Mert Mertce May 17 '20 at 16:27