17

When trying to load my app on an iOS device I get the following error;

VMundefined bundle.js:1722 SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.

This error occurred on iPhone 5s/6s + a couple of different iPad's I tried (can't remember which). It also did not work on the HTC one. This error did not occur on any samsung/windows phones I tried. It also worked on desktops. (I have not tried to run it on a mac yet).

Here is that line of code from the bundle.js;

{}],12:[function(require,module,exports){
"use strict";
const guage_1 = require("./charts/kpi/guage");
const stacked_1 = require("./charts/area/stacked");
const barChart_1 = require("./charts/compare/barChart");

When I remove the "use strict" from the bundle.js it works fine on all devices. Just wondering if there is a way to make sure typescript does not compile with "use strict" or a fix for the problem with iOS devices?

Here is my gulpfile for compiling (followed the guide published on typescripts website)

var gulp = require('gulp'),
    sourcemaps = require('gulp-sourcemaps'),
    source = require('vinyl-source-stream'),
    tsify = require('tsify'),
    browserSync = require('browser-sync'),
    postcss = require('gulp-postcss'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    rename = require('gulp-rename'),
    watchify = require("watchify"),
    browserify = require('browserify'),
    gutil = require("gulp-util"),
    buffer = require('vinyl-buffer'),
    processorArray = [
       ...
    ],
    watchedBrowserify = watchify(browserify({
        basedir: '.',
        debug: true,
        entries: ['src/main.ts'],
        cache: {},
        packageCache: {}
    }).plugin(tsify)),
    devPlugin = './src/plugins/';

function bundle() {
    return watchedBrowserify
        .bundle()
        .pipe(source('bundle.js'))
        .pipe(gulp.dest("dist"));
}

gulp.task('default', ['styles',  'browser-sync', 'watch'], bundle, function() {

    return browserify({
            basedir: '.',
            debug: true,
            entries: ['src/main.ts'],
            cache: {},
            packageCache: {}
        })
        .plugin(tsify)
        .transform("babelify")
        .bundle()
        .pipe(source('bundle.js'))
        .pipe(buffer())
        .pipe(sourcemaps.init({
            loadMaps: true
        }))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('dist'))


});

watchedBrowserify.on("update", bundle);
watchedBrowserify.on("log", gutil.log);
alexc
  • 1,250
  • 2
  • 17
  • 44

3 Answers3

40

You can do that by compiling with the --noImplicitUseStrict compiler option—add "noImplicitUseStrict": true to "compilerOptions" in tsconfig.json.

Doing so will prevent the compiler from emitting "use strict".

David Sherret
  • 101,669
  • 28
  • 188
  • 178
  • 1
    I noticed that if we declare our class inside a namespace then "use strict" does not appear. So better to declare class inside a namespace. – Asad Naeem Apr 21 '21 at 07:47
  • I call a function with `mongo[arguments.callee.name](args..)` inside a function but still get the error `TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions` with `"noImplicitUseStrict": true` in compileoption – Timo May 27 '22 at 10:41
1

Now option name to prevent compiler from emitting "use strict" is named "alwaysStrict"

0

I have just solved it. Go to tsconfig.json file, and change:

"strict": false

in "compilerOptions"