question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

intl-messageformat throwing warnings

See original GitHub issue

I’m currently building a small app using the basic rollup svelte template, and svelte-i18n, and rollup is currently throwing the following warning when I build with locale or dictionary imported.

rollup v1.23.1
bundles src/main.js → public\bundle.js...
LiveReload enabled
(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en/#error-this-is-undefined       
node_modules\intl-messageformat\lib\core.js
4: See the accompanying LICENSE file for terms.
5: */
6: var __extends = (this && this.__extends) || (function () {
                    ^
7:     var extendStatics = function (d, b) {
8:         extendStatics = Object.setPrototypeOf ||
...and 3 other occurrences
node_modules\intl-messageformat\lib\compiler.js
4: See the accompanying LICENSE file for terms.
5: */
6: var __extends = (this && this.__extends) || (function () {
                    ^
7:     var extendStatics = function (d, b) {
8:         extendStatics = Object.setPrototypeOf ||
...and 1 other occurrence

My package.json

{
  "name": "svelte-app",
  "version": "1.0.0",
  "devDependencies": {
    "npm-run-all": "^4.1.5",
    "rollup": "^1.23.0",
    "rollup-plugin-commonjs": "^10.0.0",
    "rollup-plugin-livereload": "^1.0.0",
    "rollup-plugin-node-resolve": "^5.2.0",
    "rollup-plugin-svelte": "^5.1.0",
    "rollup-plugin-terser": "^5.1.2",
    "svelte": "^3.12.0"
  },
  "dependencies": {
    "date-fns": "^2.4.1",
    "lodash": "^4.17.15",
    "sirv-cli": "^0.4.4",
    "svelte-i18n": "^1.1.2-beta",
    "svelte-routing": "^1.4.0"
  },
  "scripts": {
    "build": "rollup -c",
    "autobuild": "rollup -c -w",
    "dev": "run-p start:dev autobuild",
    "start": "sirv public --single",
    "start:dev": "sirv public --single --dev"
  }
}

Anyone have any insights here?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ashourcommented, Oct 8, 2019

Oh, and there may be a related issue in the intl-messageformat repo. It seems that the var __extends = (this && this.__extends) || (function () { code is created by TypeScript, which is the language intl-messageformat is written in, I believe. Not 100% sure about this but wanted to share in case someone wants to do a bit more digging.

1reaction
ashourcommented, Oct 8, 2019

Hello @Sureiya. Yeah this seems to be a known issue with Rollup. To be consistent with native module implementations, Rollup sets this = undefined at the top level in modules. It also displays a warning if a module tries to use this at the top level. intl-messageformat has code that uses this at the top level, which upsets Rollup.

The intl-messageformat code seems to work just fine, however, and I’ve gotten rid of the warnings by using the suggestion in the Rollup documentation to provide the two culprit modules—node_modules\intl-messageformat\lib\core.js and node_modules\intl-messageformat\lib\compiler.js—with window instead of undefined as the this value. Since all our code runs in the browser, I’m assuming the two modules expect this = window. I’ve achieve the override in my rollup.config.js:

import svelte from 'rollup-plugin-svelte';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';

const production = !process.env.ROLLUP_WATCH;

export default {
    input: 'src/main.js',
    output: {
        sourcemap: true,
        format: 'iife',
        name: 'app',
        file: 'public/bundle.js',
    },

    // 👇🏽 The added `moduleContext` key is the relevant override here.

    moduleContext: (id) => {
        const thisAsWindowForModules = [
            'node_modules/intl-messageformat/lib/core.js',
            'node_modules/intl-messageformat/lib/compiler.js',
        ];

        if (thisAsWindowForModules.some(id_ => id.trimRight().endsWith(id_))) {
            return 'window';
        }
    },

   // 👆🏽

    plugins: [
        svelte({
            // enable run-time checks when not in production
            dev: !production,
            // we'll extract any component CSS out into
            // a separate file — better for performance
            css: css => {
                css.write('public/bundle.css');
            }
        }),

        // If you have external dependencies installed from
        // npm, you'll most likely need these plugins. In
        // some cases you'll need additional configuration —
        // consult the documentation for details:
        // https://github.com/rollup/rollup-plugin-commonjs
        resolve({
            browser: true,
            dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/')
        }),
        commonjs(),

        // Watch the `public` directory and refresh the
        // browser on changes when not in production
        !production && livereload('public'),

        // If we're building for production (npm run build
        // instead of npm run dev), minify
        production && terser()
    ],
    watch: {
        clearScreen: false
    }
};

May be this should be addressed in the README doc? Happy to provide a PR if people agree.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intl MessageFormat | Format.JS
Intl MessageFormat. Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.
Read more >
intl-messageformat - npm
Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.. Latest version: 10.2.5, ...
Read more >
format-message - npm Package Health Analysis - Snyk
Internationalize text, numbers, and dates using ICU Message Format For more information about how to use this package see README.
Read more >
intl | Dart Package - Pub.dev
Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and other internationalization ...
Read more >
formatjs - Bountysource
intl -messageformat-parser: Unable to import with latest node.js and ESM enabled. ... warning: warning Reading source file from TTY. and the process hangs, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found