1

I am trying to access i18n assets in an Angular project I'm working on in TypeScript, and part of our e2e testing gets the language the app is currently in from a config. I would like to pass that language value into the require() statement so I collect the correct JSON contents based on which language is needed for that test.

This works:

const i18nAsset = require(`../../../../web/src/assets/i18n/en.json`); 

This results in the error Cannot find module '../../../../web/src/assets/i18n/en.json':

const i18nAsset = require(`../../../../web/src/assets/i18n/${"en"}.json`); 

As does this:

const i18nAsset = require("../../../../web/src/assets/i18n/" + "en" + ".json"); 

What could be causing this? If it makes a difference, my e2e project is using Browserify, and the Angular application is using Webpack.

2
  • I'm just guessing, but since the bundler never sees en.json referenced as a dependency it doesn't include it in the bundle. Commented Oct 18, 2021 at 18:14
  • This answer is probably what you're looking for. Looks like it's a limitation of Browserify. Commented Oct 18, 2021 at 20:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.