-1

There is a file ts with the following import:

import dictJsonRu from '../../assets/i18n/ru_RU.json';

After build the browser tried to find this file on my local machine using relative path.

How to make this path absolute?

I have trie this:

import dictJsonRu from 'src/assets/i18n/ru_RU.json';

My ts config is:

 "compilerOptions": {
        "baseUrl": "./"

Error is:

Fetch API cannot load file:///C:/Users/O/Desktop/Projects/ka/assets/i18n/ru_RU.json. URL scheme must be "http" or "https" for CORS request.

Also I tried this:

  "paths": {
      "@assets*": ["src/assets/*"]
   }

import dictJsonRu from '@assets/i18n/ru_RU.json';

If to set <base href="/" /> in html file I get this error:

 Fetch API cannot load file:///C:/assets/i18n/ru_RU.json. URL scheme must be "http" or "https" for CORS request.

My html file looks like this:

<body>
<app-root></app-root>
<script src="http://remoteserve/mp.js"></script>
</body>

I want to find file relative this http://remoteserve/mp.js/ssets/i18n/ru_RU.json.

I use IIS, probably I can set web.config to say where to loook files when main.js is required in client?

  • try `import dictJsonRu from 'assets/i18n/ru_RU.json';` --> I guess there is `"baseUrl": "./src",` in you "tsconfig.json" – Tino Jun 14 '21 at 10:44
  • See my question again, I posted config ts –  Jun 14 '21 at 10:45
  • So there is a difference between environments!? It works in "dev", but not in "prod" environment. Is that correct? – Tino Jun 14 '21 at 10:55
  • No I get this file not from envirement, I just import it as usual ts file –  Jun 14 '21 at 10:58
  • I have main.js output file that is placed on hosting. I create a index.html page on my localhost where placed this remote main.js file. –  Jun 14 '21 at 11:06
  • 1
    You should put everything from the ".dist/" folder on your hosting server, not just the "main.js" file – Tino Jun 14 '21 at 11:19
  • I have put everything ,problem in paths not in files –  Jun 14 '21 at 11:21
  • main.js and others files are placed on remote server –  Jun 14 '21 at 11:23
  • All right, if everything worked as expected it should work now, wenn you acces the index.html on the remote server in your browser – Tino Jun 14 '21 at 11:40
  • No it does not work, could we move in chat? –  Jun 14 '21 at 11:41
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/233748/discussion-between-coverbase-and-tino). –  Jun 14 '21 at 11:41

1 Answers1

0

You can try this way,

   "paths": {
        "@assets/*": ["src/assets/*"]
    },


import dictJsonRu from '@assets/i18n/ru_RU.json';
Zahidur Rahman
  • 1,688
  • 2
  • 20
  • 30