0

I need to import a package that has this configuration:

package.json

{
  "name": "com.matheusdiasdesouzads.js.language-objects",
  "main": "src/index.ts"
}

I'm importing this package from an outer package via:

my-outer-package/src/index.ts

import {Language} from 'com.matheusdiasdesouzads.js.language-objects';

Is it possible to keep my dependency configuration above as is and run ts-node src/index.ts? I've a project similiarly structured that runs fine in ts-node. Somehow my current project fails with this:

> ts-node src/index.ts # my-outer-package
< my-outer-package\node_modules\com.matheusdiasdesouzads.js.language-objects\src\index.ts:1
import Language, {Direction} from './language';
^^^^^^

SyntaxError: Cannot use import statement outside a module

Also note that running ts-node com.matheusdiasdesouzads.js.language-objects/src/index.ts doesn't produce this module-related error.

Here are the full sources:

I tried everything in this question: Ts-node : SyntaxError: Cannot use import statement outside a module

  • Set compilerOptions.module to "CommonJS".
  • Set compilerOptions.target to "ES2017".
  • Set compilerOptions.esModuleInterop to true.
  • Set type to "module" in package.json.
Hydroper
  • 344
  • 2
  • 9

1 Answers1

0

It is a bug probably on ts-node. When the dependency is on the file system, that is, when I replace:

"com.matheusdiasdesouzads.js.language-objects": "^1.1.0"

by:

"com.matheusdiasdesouzads.js.language-objects": "file:../language-objects-js"

My code compiles successfully (it creates a shortcut). I've commited an issue on their GitHub repository.

Hydroper
  • 344
  • 2
  • 9