使用i18next模块的Google Apps脚本错误

问题描述:

我在ES6中编写我的项目,目前正面临i18next模块的问题。 https://www.i18next.com/使用i18next模块的Google Apps脚本错误

在我的本地系统上,当我导入i18next import i18next from 'i18next';并在我的源文件中使用它时,一切正常。但是,在我运行npm run gulp(它将所有源文件合并为一个JavaScript文件 - main.js)并尝试将该代码上传到Google Apps脚本(使用gapps upload)后,它会失败,并显示Bad Request. Upload failed.错误。

在线检查后,我发现这个错误意味着有一些错误的语法,所以我试图复制粘贴main.js代码到谷歌Apps脚本,它显示了以下语法错误:

Invalid property ID. (Line 32, file "main")

第32行:

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 

即使我只是导入i18next模块,而无需实际做任何事的发生此错误。

这里是我的gulpfile

import gulp from 'gulp'; 
import browserify from 'browserify'; 
import source from 'vinyl-source-stream'; 
import mocha from 'gulp-mocha'; 

const compileFile = 'main.js'; 

gulp.task('dest',() => { 
    browserify({ 
     entries: ['src/'+compileFile] 
    }) 
    .transform('babelify') 
    .plugin('gasify') 
    .bundle() 
    .pipe(source(compileFile)) 
    .pipe(gulp.dest('dist')); 
}); 

gulp.task('test',() => { 
    gulp.src('test/**/*.js', {read: false}) 
    .pipe(mocha({ 
     reporter: 'spec', 
     compilers: 'js:babel-core/register' 
    })); 
}); 

gulp.task('default', ['test', 'dest'],() => {}); 

gulp.task('watch',() => { 
    gulp.watch('src/**/*.js', ['dest']); 
}); 

还试图用国际化的模块,不工作。

我想为我的翻译使用获取文本模块,不需要货币/日期格式自定义。只需从翻译文件中获取文本。不能使用JSON PO或任何其他分机(我需要上传的所有作为一个文件来气,不认为他们能够比.js文件以外的任何文件)

我的模板文件都是这样en.js

const res = { 
    template: { 
    "signIn":"Hello, <@#1>! Signed you in (#2)", 
    ... 
    }, 
    command: { 
    "signIn": "hi", 
    ... 
    } 
}; 
export default res; 

刚刚找到工作解决方案!

在尝试了所有的国际化库并获得各种天然气和nongas相关错误后,node-polyglot模块为我工作!

仍然不知道为什么i18next心不是工作虽然

+1

真的很奇怪......知道这个问题的路线原因很有意思。 – jamuhl

+0

是的!我在i18next回购上创建了一个问题,但被告知我应该联系谷歌应用脚​​本,因为这个问题可能与他们的方面有关。在应用程序脚本支持页面上创建了一个问题,但没有得到回复 – JapanGuy

+0

@jamuhl哦,我刚刚意识到这是你在github上跟我说的。感谢您的帮助!我在我的其他基于浏览器的项目上有i18next工作!这很棒! – JapanGuy

为ES6谷歌Apps脚本的支持是有限的原因。据我了解,GAS不包括ES5和ES6上引入的任何功能。

https://developers.google.com/apps-script/guides/services/#basic_javascript_features

Basic JavaScript features

Apps Script is based on JavaScript 1.6, plus a few features from 1.7 and 1.8. Many basic JavaScript features are thus available in addition to the built-in and advanced Google services: you can use common objects like Array, Date, RegExp, and so forth, as well as the Math and Object global objects. However, because Apps Script code runs on Google's servers (not client-side, except for HTML-service pages), browser-based features like DOM manipulation or the Window API are not available.

根据Mozilla Developer Network,JavaScript的1.6对应于ECMAScript的3(ES3)。

+0

我不知道这个,谢谢!但我认为我的gulpfile将我的源代码转换为javascript(不知道哪个版本)。而且我使用了几个不同的节点模块,并且仅在国际化模块中出现语法错误(在应用程序脚本上)。其他一切按预期工作 – JapanGuy