Skip to content

Package's main script not treated as module depending if it's file-system local or not #1876

@hydroper

Description

@hydroper

Search Terms

There's a similiar issue, #922. However it is closed and the suggested solutions don't work for me.

Expected Behavior

No error. I've confirmed this is a bug. When I change the dependency:

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

to...

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

I don't get SyntaxError: Cannot use import statement outside a module anymore.

Actual Behavior

I'm getting:

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

Steps to reproduce the problem

    1. git clone https://github.com/matheusdiasdesouzads/message-locator-js
    1. cd message-locator-js
    1. ts-node src/index.ts

Minimal reproduction

The repository https://github.com/matheusdiasdesouzads/message-locator-js is pretty short and only depends on https://github.com/matheusdiasdesouzads/language-objects-js, which is also short.

Specifications

  • ts-node version: v10.9.1
  • node version: v16.17.0
  • TypeScript version: v4.7.4
  • tsconfig.json, if you're using one:
{
  "compilerOptions": {
    "out": "dist/message-locator.js", 
    "sourceMap": true, 
    "target": "es6",
    "lib": ["es2015", "dom"],
    "noImplicitAny": true
  }
}
  • package.json:
{
  "name": "com.matheusdiasdesouzads.js.message-locator",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "matheusdiasdesouzads",
  "repository": "https://github.com/matheusdiasdesouzads/message-locator-js",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.27.2",
    "com.matheusdiasdesouzads.js.language-objects": "^1.1.0"
  }
}
  • Operating system and version: Windows 10 21H2 build 19044.1288
  • If Windows, are you using WSL or WSL2?:
    Windows 10, not WSL.

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