Skip to content

[Webpack] env.sourceMap, if not specified, is unexpectedly true by default (at least for tns run ios) #9231

@shirakaba

Description

@shirakaba

Environment

$ tns info
✔ Getting NativeScript components versions information...
⚠ Update available for component nativescript. Your current version is 7.1.0 and the latest available version is 7.2.0.
⚠ Update available for component @nativescript/core. Your current version is 7.0.13 and the latest available version is 7.2.1.
✔ Component @nativescript/ios has 7.2.0 version and is up to date.
✔ Component @nativescript/android has 7.0.1 version and is up to date.

Describe the bug

tns run ios --no-hmr
// In `webpack.config.js`, e.g. in a React NativeScript project
module.exports = (env) => {
    env = env || {};

    console.log(`env.sourceMap: ${env.sourceMap}; env.hiddenSourceMap: ${env.hiddenSourceMap}`);
    // Despite the sourceMap flag not having been passed in, this prints:
    //    env.sourceMap: true; env.hiddenSourceMap: undefined

    const baseConfig = webpackConfig(env);
    // console.log(baseConfig);
    // ...
}
// See how we get:
//    devtool: 'inline-source-map',
// ... when I'd expect it to be:
//    devtool: 'none'
{
  mode: 'development',
  context: '/Users/jamie/Documents/git/react-native-in-nativescript/apps/demo-react/src',
  externals: [ /^~\/package.json((\/.*)|$)/, /^package.json((\/.*)|$)/ ],
  watchOptions: {
    ignored: [
      '/Users/jamie/Documents/git/react-native-in-nativescript/tools/assets/App_Resources',
      '**/.*'
    ]
  },
  target: [Function: nativescriptTarget],
  entry: {
    bundle: './app.ts',
    'tns_modules/@nativescript/core/inspector_modules': 'inspector_modules'
  },
  output: {
    pathinfo: false,
    path: '/Users/jamie/Documents/git/react-native-in-nativescript/apps/demo-react/platforms/ios/demoreact/app',
    sourceMapFilename: '[file].map',
    libraryTarget: 'commonjs2',
    filename: '[name].js',
    globalObject: 'global',
    hashSalt: '1613827376957'
  },
  resolve: {
    extensions: [ '.ts', '.js', '.scss', '.css' ],
    modules: [
      '/Users/jamie/Documents/git/react-native-in-nativescript/apps/demo-react/node_modules/@nativescript/core',
      '/Users/jamie/Documents/git/react-native-in-nativescript/apps/demo-react/node_modules',
      'node_modules/@nativescript/core',
      'node_modules'
    ],
    alias: {
      '~/package.json': '/Users/jamie/Documents/git/react-native-in-nativescript/apps/demo-react/package.json',
      '~': '/Users/jamie/Documents/git/react-native-in-nativescript/apps/demo-react/src',
      'tns-core-modules': '@nativescript/core'
    },
    symlinks: true
  },
  resolveLoader: { symlinks: false },
  node: {
    http: false,
    timers: false,
    setImmediate: false,
    fs: 'empty',
    __dirname: false
  },
  devtool: 'inline-source-map',
  optimization: {
    runtimeChunk: 'single',
    noEmitOnErrors: false,
    splitChunks: { cacheGroups: [Object] },
    minimize: false,
    minimizer: [ [TerserPlugin] ]
  },
  module: {
    rules: [ [Object], [Object], [Object], [Object], [Object], [Object] ]
  },
  plugins: [
    DefinePlugin { definitions: [Object] },
    CleanWebpackPlugin {
      dangerouslyAllowCleanPatternsOutsideProject: false,
      dry: false,
      verbose: false,
      cleanStaleWebpackAssets: true,
      protectWebpackAssets: true,
      cleanAfterEveryBuildPatterns: [],
      cleanOnceBeforeBuildPatterns: [Array],
      currentAssets: [],
      initialClean: false,
      outputPath: '',
      apply: [Function: bound apply],
      handleInitial: [Function: bound handleInitial],
      handleDone: [Function: bound handleDone],
      removeFiles: [Function: bound removeFiles]
    },
    { apply: [Function: apply] },
    GenerateNativeScriptEntryPointsPlugin {
      appEntryName: 'bundle',
      files: {}
    },
    NativeScriptWorkerPlugin {
      options: {},
      [Symbol(NATIVESCRIPT_WORKER_PLUGIN_SYMBOL)]: true
    },
    PlatformFSPlugin {
      platform: 'ios',
      platforms: [Array],
      ignore: []
    },
    WatchStateLoggerPlugin {},
    ForkTsCheckerWebpackPlugin { options: [Object] }
  ]
}

To Reproduce

tns run ios --no-hmr

Expected behavior

As the docs for tns run ios suggest that the env flags are to be passed explicitly, I'd expect that you'd need to pass in the env.sourceMap flag explicitly.

Sample project

Just create a fresh NativeScript project. In my case, I was creating a React project.

Additional context

I'd expect source maps to be off by default, as they increase the build time. In my case, they generate a file larger than 10 MB. Just to characterise things, here's the existing behaviour:

# All of these currently cause env.sourceMap to evaluate as true in the Webpack config,
# and thus set devtool to "inline-sourcemap":

# No flag at all
tns run ios --no-hmr

# With flag but no value
tns run ios --no-hmr --env.sourceMap

# With flag and value
tns run ios --no-hmr --env.sourceMap true

Workaround

To turn off source maps, instead run your app like this:

tns run ios --no-hmr --env.sourceMap false

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions