-
Notifications
You must be signed in to change notification settings - Fork 74
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
intl-messageformat throwing warnings #12
Comments
Hello @Sureiya. Yeah this seems to be a known issue with Rollup. To be consistent with native module implementations, Rollup sets 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— 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. |
Oh, and there may be a related issue in the intl-messageformat repo. It seems that the |
As @ashour explained better than I ever could, this is a known issue related to rollup + |
Thanks for the well documented code @ashour! I was aware of the cause and that fix, but something seems fishy here, and I think we might be overlooking something. I've went over the rollup config for formatjs and it seems fine there. The reason I reported this here is that I can't find any mention of this elsewhere, and I would have expected to see some issue on formatjs. I've been playing all day trying to resolve this. I thought I had it fixed at one point using some different import strategies. One thing I haven't tried is giving rollup a new build target and having it fix the intl-messageformat in node_modules before building the library. Another solution would be to remove it as an external module and add the moduleContext code ashour provided. This increases the bundle size, but I believe this would end up being bundled with it anyway in the end unless I'm wrong? |
Quick update about this: i started messing around with the continues looking For now, we have this: rollup/rollup#794 (comment). A custom |
Thanks for the explanations! But event with @ashour code I have the same warning. Added, but I don't know if related, I also have the following error:
I use
And my rollup.config.js is
My assumption is that I'm using/importing something the wrong way. Any help is appreciated! |
I couldn't find
And still getting the error after updating rollup.conf Here is my current package setup {
"name": "altas",
"description": "Atlas HR Portal",
"version": "0.0.2",
"scripts": {
"dev": "sapper dev",
"build": "sapper build --legacy",
"export": "sapper export --legacy",
"start": "node __sapper__/build",
"cy:run": "cypress run",
"cy:open": "cypress open",
"test": "run-p --race dev cy:run"
},
"dependencies": {
"axios": "^0.19.0",
"compression": "^1.7.1",
"mobile-pull-to-refresh": "^0.2.2",
"moment": "^2.24.0",
"plyr": "^3.5.6",
"polka": "^0.5.0",
"qs": "^6.9.1",
"sirv": "^0.4.0",
"svelte-i18n": "^2.1.1"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/runtime": "^7.0.0",
"@rollup/plugin-json": "^4.0.0",
"npm-run-all": "^4.1.5",
"rollup": "^1.12.0",
"rollup-plugin-babel": "^4.0.2",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-svelte": "^5.0.1",
"rollup-plugin-terser": "^4.0.4",
"sapper": "^0.27.0",
"svelte": "^3.0.0"
},
"keywords": []
} Using intl-messageformat 7.8.0 |
A workaround was added to the FAQ section of the wiki: https://github.com/kaisermann/svelte-i18n/wiki/FAQ#this-keyword-is-equivalent-to-undefined It's best to add a condition to ignore this kind of warning and forget about it 😁 . @omirobarcelo What you're getting is related to how |
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.
My package.json
Anyone have any insights here?
The text was updated successfully, but these errors were encountered: