Closed fynncfchen closed 4 years ago
ohhh.... old browser version... But I'm not able to reproduce it... I also tried v33... Can you create a reproducable example? Can you try a PR? Or propose a concrete code change?
Found a possible cause:
I use Parcel as our bundler, and the order they're use are
Means that the resolver will use a not-bundled version of package (./lib/index.js
)
which using a ES6+ syntax.
That's very different from the i18next-xhr-backend
:
which use a bundled version of package:
import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
import _createClass from '@babel/runtime/helpers/esm/createClass';
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
import _typeof from '@babel/runtime/helpers/esm/typeof';
var arr = [];
var each = arr.forEach;
var slice = arr.slice;
function defaults(obj) {
each.call(slice.call(arguments, 1), function (source) {
if (source) {
for (var prop in source) {
if (obj[prop] === undefined) obj[prop] = source[prop];
}
}
});
return obj;
}
There's a solution to solve this problem: use a browser
field in package.json
to tell a bundler to use for browser:
https://parceljs.org/module_resolution.html#package.json-%60browser%60-field
I suggest to provide a migration notes in document for replacing the deprecated i18next-xhr-backend
with a different Behavior.
A little question: Is your parcel setup not babeling the files? (I've never used parcel)
AFAIK the current stable version (v1) of Parcel doesn't have the option to include some of the package should be compiled, which means we should assume that all packages in node_modules
are bundled.
Another approach to solve this issue is to import the cjs
version of this package explicitly:
import Backend from 'i18next-http-backend/cjs';
Ok, didn't know Parcel is not able to transpile it... ok...
importing import Backend from 'i18next-http-backend/cjs';
is a valid solution 👍
Unfortunately after some clean up and test, I found the solution from above not work anymore, even if I use
import Backend from 'i18next-http-backend/i18nextHttpBackend';
I think it might not to use any require
in a bundled version CJS module, should be like i18next-xhr-backend
do - bundle an internal AJAX inside.
because I got this new message:
TypeError: global.fetch is undefined
I'll go back to use i18next-xhr-backend
anyway.
@fynncfchen if you create a reproducable example I can try to help. i18next-xhr-request will not get any more updates, so it would be better to fix this here...
I found it's hard to reproduce by myself also, sorry..... I'll dig into my project to find the real problem and feedback to you, thanks for help!
This is my playground: https://github.com/adrai/parcel-example-i18next-http-backend maybe you can reproduce it there
Good news! I finally can reproduce what I've got!
https://github.com/fynncfchen/i18next-http-backend-issue
You can yarn
then yarn start
and see if the dist
folder has a getFetch.[hash].cjs
, also check at i18next-http-backend-issue.[hash].js
you can find some ES6+ syntax there.
Open http://localhost:1234
on Firefox 34, you can see an syntax error just what I've reported.
This is because you’re importing like: import Backend from "i18next-http-backend"; Try: import Backend from "i18next-http-backend/cjs";
If you need a transpiled source (seems by default for parcel this is the case), you need to import /cjs
I'm not sure what happened but after I deleted yarn.lock
and re-install all packages, the /cjs
version works on my project.
Maybe the problem coming from the dependence tree....
In your example: https://github.com/fynncfchen/i18next-http-backend-issue you are not importing cjs
I know, when I importing cjs
in my example and it works, but in my real project it failed. I think the dependencies are different.
I found that ^1.0.8
not work for cjs
, but the latest version works!
fyi: With the latest version importing with /cjs
should not be necessary anymore.
🐛 Bug Report
Firefox 34 got syntax error, the file compiled by Babel are not use older syntax.
Compiled file:
To Reproduce
i18next-xhr-backend
for the first time withi18n.js
i18n .use(Backend) .use(LanguageDetector) .use(initReactI18next) .init();
Expected behavior
Use both
i18next-xhr-backend
andi18next-http-backend
should be work fine.Your Environment
package.json
.babelrc
.browserslistrc