Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic imports not working on built project - only on the dev server #5118

Closed
Taxi4you opened this issue Sep 9, 2020 · 2 comments
Closed
Labels
Stale Inactive issues

Comments

@Taxi4you
Copy link

Taxi4you commented Sep 9, 2020

#4782 馃悰 bug report

When I run parcel index.html (run dev server) the dynamic imports are working
When I run parcel build index.html (build static files for browser) the dynamic imports are not working.

This is the dynamic import I am trying to do:

const translations = await import('/en-us/translations.json')
await import('ltr-framework-bundle.css')
await import('/colors.css')

馃帥 Configuration (.babelrc, package.json, cli command)

"dependencies": {
    "babel-polyfill": "^6.26.0"
  },
  "devDependencies": {
    "parcel-bundler": "^1.12.4",
    "sass": "^1.26.8"
  }

There is no .babelrc or babel.config.js file.

馃 Expected Behavior

First it should be working.
Second it should be work instead of this:

const translations = await import('/en-us/translations.json')
await import('ltr-framework-bundle.css')

but like this:

const translations = await import(`/${language}/translations.json`)
await import(`${direction}-framework-bundle.css`)

馃槸 Current Behavior

I got the following error when running the static files in browser (under http-server, of course):

Unhandled Promise Rejection: Error: Cannot find module 'irlt'

Well.. obviously - the browser doesn't know how to handle this promise which is not transformed to es5 in the build stage.

馃敠 Context

I want to load specific files based on the locale of the user - if the user is from USA I will load English and LTR css files.
If the user is from Israel I will load Hebrew and RTL css files. etc.

So as you can see, I need to load the specific css file respectively.

馃捇 Code Sample

  if (new_language=="he-IL") {
      language.current = "he-IL"
      language.t = await import('/app/locales/he-IL/translations.json')
      await import('framework7/css/framework7.bundle.rtl.css')
    }
    if (new_language=="en-US") {
      language.current = "en-US"
      language.t = await import('/app/locales/en-US/translations.json')
      await import('framework7/css/framework7.bundle.css')
    }
    global.SetMonthAndDaysNames()
    await import('/colors.css')
    document.getElementsByTagName("html")[0].dir = language.t.dir
    return typeof cb !== "undefined" ? cb() : location.reload()
@AndrewKvalheim
Copy link
Contributor

Possibly the same issue as #2515

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

@github-actions github-actions bot added the Stale Inactive issues label May 25, 2021
@github-actions github-actions bot closed this as completed Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Inactive issues
Projects
None yet
Development

No branches or pull requests

2 participants