Skip to content

Node breaks when switching branches ; Invalid or Unexpected Token #1470

Description

@gita-vahdatinia

Search Terms

cjs-loader
Invalid or unexpected token
cache corruption

Expected Behavior

Not error out

Actual Behavior

Seemingly random get syntax error for unexpected or invalid token thrown by node coming from ts-node. It happens when I switch branches or do updates to node modules, hard to reproduce because it seemingly does not happen every time. I can resolve by wiping out ts-node cache or adding a space to that file will help resolve.
Here is stack call

2021-06-23-10:13:15 11|workflow_server  | SyntaxError: Invalid or unexpected token
2021-06-23-10:13:15 11|workflow_server  |     at wrapSafe (internal/modules/cjs/loader.js:1001:16)
2021-06-23-10:13:15 11|workflow_server  |     at Module._compile (internal/modules/cjs/loader.js:1049:27)
2021-06-23-10:13:15 11|workflow_server  |     at Module.m._compile (/Users/person/src/code/node_modules/ts-node/src/index.ts:439:23)
2021-06-23-10:13:15 11|workflow_server  |     at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-06-23-10:13:15 11|workflow_server  |     at Object.require.extensions.<computed> [as .ts] (/Users/person/src/code/node_modules/ts-node/src/index.ts:442:12)
2021-06-23-10:13:15 11|workflow_server  |     at Module.load (internal/modules/cjs/loader.js:950:32)
2021-06-23-10:13:15 11|workflow_server  |     at Function.Module._load (internal/modules/cjs/loader.js:790:14)
2021-06-23-10:13:15 11|workflow_server  |     at Module.require (internal/modules/cjs/loader.js:974:19)
2021-06-23-10:13:15 11|workflow_server  |     at Module.Hook._require.Module.require (/Users/person/src/code/node_modules/require-in-the-middle/index.js:80:39)
2021-06-23-10:13:15 11|workflow_server  |     at require (internal/modules/cjs/helpers.js:92:18)
2021-06-23-10:13:15 11|workflow_server  |     at Object.<anonymous> (/Users/person/src/code/modules/server/aws/factory.ts:23:1)
2021-06-23-10:13:15 11|workflow_server  |     at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-06-23-10:13:15 11|workflow_server  |     at Module.m._compile (/Users/person/src/code/node_modules/ts-node/src/index.ts:439:23)
2021-06-23-10:13:15 11|workflow_server  |     at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-06-23-10:13:15 11|workflow_server  |     at Object.require.extensions.<computed> [as .ts] (/Users/person/src/code/node_modules/ts-node/src/index.ts:442:12)
2021-06-23-10:13:15 11|workflow_server  |     at Module.load (internal/modules/cjs/loader.js:950:32)
2021-06-23-10:13:15 11|workflow_server  |     at Function.Module._load (internal/modules/cjs/loader.js:790:14)
2021-06-23-10:13:15 11|workflow_server  |     at Module.require (internal/modules/cjs/loader.js:974:19)
2021-06-23-10:13:15 11|workflow_server  |     at Module.Hook._require.Module.require (/Users/person/src/code/node_modules/require-in-the-middle/index.js:80:39)
2021-06-23-10:13:15 11|workflow_server  |     at require (internal/modules/cjs/helpers.js:92:18)
2021-06-23-10:13:15 11|workflow_server  |     at Object.<anonymous> (/Users/person/src/code/modules/server/services-builder/services_builder.ts:39:1)
2021-06-23-10:13:15 11|workflow_server  |     at Module._compile (internal/modules/cjs/loader.js:1085:14)

Steps to reproduce the problem

Hard to reproduce since it is seemingly flakey.

Specifications

ts-node v7.0.1
node v14.17.6
typescript v4.4.3
cache "/Users/gita/code/coda/build/ts-node-cache/87243488a73d3353973082673ab4a19d1295ce03e37210783044f24f533dd39e"

  • tsconfig.json, if you're using one:
{
  "compilerOptions": {
    /* Basic Options */
    "target": "ES2019",                       /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
    "lib": [                                  /* Specify library files to be included in the compilation:  */
      "dom",
      "dom.iterable",
      "scripthost",
      "es2019",
      "es2020.promise"
    ],
    "allowJs": true,                          /* Allow javascript files to be compiled. */
    "checkJs": false,                         /* Report errors in .js files. */
    "jsx": "react-jsx",                           /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
    // "declaration": true,                   /* Generates corresponding '.d.ts' file. */
    // "sourceMap": true,                        /* Generates corresponding '.map' file. */
    // "outFile": "./",                       /* Concatenate and emit output to single file. */
    "outDir": "./typescript",                 /* Redirect output structure to the directory. */
    // "rootDir": "./",                       /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    // "removeComments": true,                /* Do not emit comments to output. */
    // "noEmit": true,                        /* Do not emit outputs. */
    // "importHelpers": true,                 /* Import emit helpers from 'tslib'. */
    // "downlevelIteration": true,            /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
    // "isolatedModules": true,               /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

    // "preserveConstEnums": true,

    /* Strict Type-Checking Options */
    "strict": true,                           /* Enable all strict type-checking options. */
    "noImplicitAny": true,                    /* Raise error on expressions and declarations with an implied 'any' type. */
    // "strictNullChecks": true,              /* Enable strict null checks. */
    // "noImplicitThis": true,                /* Raise error on 'this' expressions with an implied 'any' type. */
    // "alwaysStrict": true,                  /* Parse in strict mode and emit "use strict" for each source file. */
    "resolveJsonModule": true,                /* Resolve types from imported JSON files. */
    "esModuleInterop": true,                  /* Handle CommonJS module imports as expected. */

    /* Additional Checks */
    "noUnusedLocals": true,                   /* Report errors on unused locals. */
    // "noUnusedParameters": true,            /* Report errors on unused parameters. */
    // "noImplicitReturns": true,             /* Report error when not all code paths in function return a value. */
    // "noFallthroughCasesInSwitch": true,    /* Report errors for fallthrough cases in switch statement. */
    "noImplicitOverride": true,

    /* Module Resolution Options */
    "moduleResolution": "node",               /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
    "baseUrl": "./",                          /* Base directory to resolve non-absolute module names. */
    "paths": {
      "@kr-modules/*": ["./modules/*"],
      "*": ["./types/modules/*"]
    },                                        /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
    // "rootDirs": [],                        /* List of root folders whose combined content represents the structure of the project at runtime. */
    // "typeRoots": [],                       /* List of folders to include type definitions from. */
    // "types": [],                           /* Type declaration files to be included in compilation. */
    // "allowSyntheticDefaultImports": true,  /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */

    /* Source Map Options */
    // "sourceRoot": "./",                    /* Specify the location where debugger should locate TypeScript files instead of source locations. */
    // "mapRoot": "./",                       /* Specify the location where debugger should locate map files instead of generated locations. */
    // "inlineSourceMap": true,               /* Emit a single file with source maps instead of having a separate file. */
    // "inlineSources": true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

    /* Experimental Options */
    "experimentalDecorators": true            /* Enables experimental support for ES7 decorators. */
    // "emitDecoratorMetadata": true,         /* Enables experimental support for emitting type metadata for decorators. */
  },
  "include": [
    "./types/**/*.d.ts",
    "./modules/**/*",
    "./*",
    "./scripts/**/*",
    "./tools/**/*"
  ],
  "exclude": [
    ".happypack",
    "artifacts",
    "build",
    "data",
    "logs",
    "node_modules",
    "reports"
  ],
  "files": [
    "./node_modules/sugar-date/sugar.d.ts",
    "./node_modules/emoji-regex/index.d.ts"
  ]
}

  • Operating system and version:
    MacOS 10.15.7

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions