svelte-i18n - Svelte Rollup 编译器警告:`this` 已被重写为 `undefined`
svelte-i18n - Svelte Rollup compiler warning: `this` has been rewritten to `undefined`
自从我在我的 Svelte 应用程序上安装了 svelte-i18n
库后,我在编译 Rollup 时遇到了以下警告。
(!) `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 __assign = (this && this.__assign) || function () {
^
7: __assign = Object.assign || function(t) {
8: for (var s, i = 1, n = arguments.length; i < n; i++) {
...and 1 other occurrence
node_modules\intl-messageformat\lib\formatters.js
1: var __extends = (this && this.__extends) || (function () {
^
2: var extendStatics = function (d, b) {
3: extendStatics = Object.setPrototypeOf ||
...and 3 other occurrences
node_modules\intl-format-cache\lib\index.js
4: See the accompanying LICENSE file for terms.
5: */
6: var __spreadArrays = (this && this.__spreadArrays) || function () {
^
7: for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
8: for (var r = Array(s), k = 0, i = 0; i < il; i++)
...and 1 other occurrence
...and 3 other files
created public\build\bundle.js in 1.3s
我相信这个错误即使与这里描述的不一样也非常相似:
https://github.com/kaisermann/svelte-i18n/blob/master/docs/FAQ.md#this-keyword-is-equivalent-to-undefined
本申请中提到的库有以下版本:
"svelte": 3.22.2
"svelte-i18n": 3.0.3
这个警告似乎不是问题,但是对我来说却非常烦人。
我真的不喜欢他们在这种情况下给出的解决方案(“学会忍受那个警告并忽略它”)。有没有什么方法可以指示编译器忽略该错误或有人已经设法修复它?
编辑:
我的问题出在 windows(因此是反斜杠),库如下:
'node_modules\intl-messageformat\lib\core.js',
'node_modules\intl-messageformat\lib\compiler.js',
'node_modules\intl-messageformat\lib\formatters.js',
'node_modules\intl-format-cache\lib\index.js',
'node_modules\intl-messageformat-parser\lib\skeleton.js',
'node_modules\intl-messageformat-parser\lib\normalize.js',
'node_modules\intl-messageformat-parser\lib\parser.js',
我在 article 中找到了一个解决方案,他们链接了必要的 Rollup 配置。基本上你需要将它添加到 rollup.config.js
:
moduleContext: (id) => {
// In order to match native module behaviour, Rollup sets `this`
// as `undefined` at the top level of modules. Rollup also outputs
// a warning if a module tries to access `this` at the top level.
// The following modules use `this` at the top level and expect it
// to be the global `window` object, so we tell Rollup to set
// `this = window` for these modules.
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';
}
}
自从我在我的 Svelte 应用程序上安装了 svelte-i18n
库后,我在编译 Rollup 时遇到了以下警告。
(!) `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 __assign = (this && this.__assign) || function () {
^
7: __assign = Object.assign || function(t) {
8: for (var s, i = 1, n = arguments.length; i < n; i++) {
...and 1 other occurrence
node_modules\intl-messageformat\lib\formatters.js
1: var __extends = (this && this.__extends) || (function () {
^
2: var extendStatics = function (d, b) {
3: extendStatics = Object.setPrototypeOf ||
...and 3 other occurrences
node_modules\intl-format-cache\lib\index.js
4: See the accompanying LICENSE file for terms.
5: */
6: var __spreadArrays = (this && this.__spreadArrays) || function () {
^
7: for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
8: for (var r = Array(s), k = 0, i = 0; i < il; i++)
...and 1 other occurrence
...and 3 other files
created public\build\bundle.js in 1.3s
我相信这个错误即使与这里描述的不一样也非常相似: https://github.com/kaisermann/svelte-i18n/blob/master/docs/FAQ.md#this-keyword-is-equivalent-to-undefined
本申请中提到的库有以下版本:
"svelte": 3.22.2
"svelte-i18n": 3.0.3
这个警告似乎不是问题,但是对我来说却非常烦人。 我真的不喜欢他们在这种情况下给出的解决方案(“学会忍受那个警告并忽略它”)。有没有什么方法可以指示编译器忽略该错误或有人已经设法修复它?
编辑:
我的问题出在 windows(因此是反斜杠),库如下:
'node_modules\intl-messageformat\lib\core.js',
'node_modules\intl-messageformat\lib\compiler.js',
'node_modules\intl-messageformat\lib\formatters.js',
'node_modules\intl-format-cache\lib\index.js',
'node_modules\intl-messageformat-parser\lib\skeleton.js',
'node_modules\intl-messageformat-parser\lib\normalize.js',
'node_modules\intl-messageformat-parser\lib\parser.js',
我在 article 中找到了一个解决方案,他们链接了必要的 Rollup 配置。基本上你需要将它添加到 rollup.config.js
:
moduleContext: (id) => {
// In order to match native module behaviour, Rollup sets `this`
// as `undefined` at the top level of modules. Rollup also outputs
// a warning if a module tries to access `this` at the top level.
// The following modules use `this` at the top level and expect it
// to be the global `window` object, so we tell Rollup to set
// `this = window` for these modules.
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';
}
}