diff --git a/js/compiler/compiler.go b/js/compiler/compiler.go index f0f9d7acc11..65fa45e6d8f 100644 --- a/js/compiler/compiler.go +++ b/js/compiler/compiler.go @@ -251,7 +251,15 @@ func (c *Compiler) compileImpl( return nil, code, err } // the compatibility mode "decreases" here as we shouldn't transform twice - return c.compileImpl(code, filename, wrap, lib.CompatibilityModeBase, state.srcMap) + var prg *sobek.Program + prg, code, err = c.compileImpl(code, filename, wrap, lib.CompatibilityModeBase, state.srcMap) + if err == nil && strings.Contains(src, "module.exports") { + c.logger.Warningf( + "While compiling %q it was noticed that it mixes import/export syntax (ESM) and commonJS module.exports. "+ + "This isn't standard behaviour and will soon not work. Please use one or the other.", + filename) + } + return prg, code, err } if compatibilityMode == lib.CompatibilityModeExperimentalEnhanced { diff --git a/js/compiler/compiler_test.go b/js/compiler/compiler_test.go index 22c90503518..7f4cb6e89d8 100644 --- a/js/compiler/compiler_test.go +++ b/js/compiler/compiler_test.go @@ -241,3 +241,26 @@ func TestMinimalSourceMap(t *testing.T) { require.NoError(t, err) require.Empty(t, hook.Drain()) } + +func TestMixingImportExport(t *testing.T) { + t.Parallel() + logger := logrus.New() + logger.SetLevel(logrus.DebugLevel) + logger.Out = io.Discard + hook := testutils.NewLogHook(logrus.InfoLevel, logrus.WarnLevel) + logger.AddHook(hook) + + compiler := New(logger) + compiler.Options = Options{ + CompatibilityMode: lib.CompatibilityModeExtended, + Strict: true, + } + _, _, err := compiler.Compile("export let s = 5;\nmodule.exports = 'something';", "somefile", false) + require.NoError(t, err) + entries := hook.Drain() + require.Len(t, entries, 1) + msg, err := entries[0].String() // we need this in order to get the field error + require.NoError(t, err) + + require.Contains(t, msg, `it was noticed that it mixes`) +}