logo
  • Guide
  • Config
  • Plugin
  • API
  • Examples
  • Community
  • Modern.js 2.x Docs
  • English
    • 简体中文
    • English
    • Configuration
      dev
      assetPrefix
      beforeStartUrl
      client
      hmr
      host
      https
      lazyCompilation
      liveReload
      port
      progressBar
      setupMiddlewares
      startUrl
      watchFiles
      writeToDisk
      bff
      prefix
      html
      appIcon
      crossorigin
      favicon
      inject
      meta
      mountId
      outputStructure
      scriptLoading
      tags
      templateParameters
      template
      title
      tools
      autoprefixer
      babel
      bundlerChain
      cssExtract
      cssLoader
      devServer
      htmlPlugin
      less
      lightningcssLoader
      minifyCss
      postcss
      rspack
      sass
      styleLoader
      swc
      tsChecker
      source
      aliasStrategy
      alias
      configDir
      decorators
      define
      disableDefaultEntries
      enableAsyncEntry
      entriesDir
      entries
      exclude
      globalVars
      include
      mainEntryName
      preEntry
      transformImport
      resolve
      aliasStrategy
      alias
      conditionNames
      dedupe
      extensions
      server
      baseUrl
      port
      publicRoutes
      routes
      ssrByEntries
      ssr
      output
      assetPrefix
      assetsRetry
      charset
      cleanDistPath
      convertToRem
      copy
      cssModules
      dataUriLimit
      disableCssModuleExtension
      disableInlineRuntimeChunk
      disableSvgr
      disableTsChecker
      distPath
      enableAssetManifest
      enableCssModuleTSDeclaration
      disableInlineRouteManifests
      externals
      filenameHash
      filename
      injectStyles
      inlineScripts
      inlineStyles
      legalComments
      minify
      overrideBrowserslist
      polyfill
      sourceMap
      splitRouteChunks
      ssg
      ssgByEntries
      svgDefaultExport
      tempDir
      plugins
      security
      checkSyntax
      nonce
      sri
      runtime
      Introduce
      plugins
      router
      performance
      buildCache
      bundleAnalyze
      chunkSplit
      dnsPrefetch
      preconnect
      prefetch
      preload
      printFileSize
      profile
      removeConsole
      removeMomentLocale
      experiments
      sourceBuild
      builderPlugins
      📝 Edit this page
      Previous pagepluginsNext pagenonce

      #security.checkSyntax

      • Type:
      type CheckSyntax =
        | boolean
        | {
            targets?: string[];
            exclude?: RegExp | RegExp[];
            ecmaVersion?: EcmaVersion;
          };
      • Default: false

      Used to analyze whether there is incompatible advanced syntax in the build artifacts under the current browser scope. If any incompatible syntax is found, detailed information will be printed to the terminal.

      #Enable Detection

      You can set checkSyntax to true to enable syntax checking.

      export default {
        security: {
          checkSyntax: true,
        },
      };

      When you enable checkSyntax, Modern.js will perform the detection during production builds. If any incompatible advanced syntax is detected in the build artifacts, error logs will be printed to the terminal, and the current build process will be terminated.

      #Error Logs

      The format of the error logs is as follows, including the source file, artifact location, error reason, and source code:

      error   [Syntax Checker] Find some syntax errors after production build:
      
        Error 1
        source:  /node_modules/foo/index.js:1:0
        output:  /dist/static/js/main.3f7a4d7e.js:2:39400
        reason:  Unexpected token (1:178)
        code:
           9 |
          10 | var b = 2;
          11 |
        > 12 | console.log(() => {
          13 |   return a + b;
          14 | });
          15 |
      Tip

      Currently, syntax checking is implemented based on AST parser. Each time it performs a check, it can only identify the first incompatible syntax found in the file. If there are multiple incompatible syntaxes in the file, you need to fix the detected syntax and re-run the check. If the corresponding source location is not shown in the log, try setting output.minify to false and rebuild again.

      #Solutions

      If a syntax error is detected, you can handle it in the following ways:

      • If you want to downgrade this syntax to ensure good code compatibility, you can compile the corresponding module through the source.include config.
      • If you don't want to downgrade the syntax, you can adjust the project's browserslist to match the syntax.
      • If you do not want to check the syntax of certain products, you can use the checkSyntax.exclude configuration to exclude the files to be checked.

      #Options

      security.checkSyntax is implemented based on @rsbuild/plugin-check-syntax. For specific options, please refer to @rsbuild/plugin-check-syntax.