Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import npm:@mobily/[email protected] #17231

Closed
scarf005 opened this issue Dec 31, 2022 · 2 comments
Closed

Cannot import npm:@mobily/[email protected] #17231

scarf005 opened this issue Dec 31, 2022 · 2 comments
Assignees
Labels
invalid what appeared to be an issue with Deno wasn't node compat

Comments

@scarf005
Copy link
Contributor

To reproduce

import { A } from 'npm:@mobily/[email protected]'
// however, this will work
// import { A } from "https://esm.sh/@mobily/[email protected]"

console.log(A.zip)

would there be a reason why esm.sh works but npm: specifier does not?

Error log

error: 'import', and 'export' cannot be used outside of module code at file:///home/scarf/.cache/deno/npm/registry.npmjs.org/@mobily/ts-belt/3.13.1/dist/esm/index.js:1:1

index.js

// file:///home/scarf/.cache/deno/npm/registry.npmjs.org/@mobily/ts-belt/3.13.1/dist/esm/index.js:1:1
import { pipe } from "./pipe.js";
import { flow } from "./flow.js";
import * as F from "./Function";
import * as A from "./Array";
import * as R from "./Result";
import * as G from "./Guards";
import * as O from "./Option";
import * as S from "./String";
import * as D from "./Dict";
import * as B from "./Bool";
import * as N from "./Number";
export {
  A,
  B,
  D,
  F,
  G,
  N,
  O,
  R,
  S,
  flow,
  pipe
};
@bartlomieju bartlomieju added needs investigation requires further investigation before determining if it is an issue or not node compat labels Jan 3, 2023
@aW4KeNiNG
Copy link

@scarf005 did you find any solution using npm?

@dsherret dsherret changed the title 'import', and 'export' cannot be used outside of module code when importing from npm Cannot import npm:@mobily/[email protected] Oct 21, 2024
@dsherret dsherret added invalid what appeared to be an issue with Deno wasn't and removed needs investigation requires further investigation before determining if it is an issue or not labels Oct 21, 2024
@dsherret
Copy link
Member

Investigated and this package's ESM build is broken and doesn't work in Node.js either.

> touch package.json
> deno install npm:@mobily/[email protected]
> echo 'import * as test from '@mobily/ts-belt'; console.log(test)' > main.mjs
> deno run main.mjs
error: [ERR_UNSUPPORTED_DIR_IMPORT] Directory import 'file:///V:/scratch/node_modules/.deno/@[email protected]/node_modules/@mobily/ts-belt/dist/esm/Function' is not supported resolving ES modules imported from 'file:///V:/scratch/node_modules/.deno/@[email protected]/node_modules/@mobily/ts-belt/dist/esm/index.js'
> node main.mjs
(node:39952) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
V:\scratch\node_modules\.deno\@[email protected]\node_modules\@mobily\ts-belt\dist\esm\index.js:1
import { pipe } from "./pipe.js";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (node:internal/modules/cjs/loader:1376:18)
    at Module._compile (node:internal/modules/cjs/loader:1405:20)
    at Module._extensions..js (node:internal/modules/cjs/loader:1544:10)
    at Module.load (node:internal/modules/cjs/loader:1275:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:212:19)
    at cjsLoader (node:internal/modules/esm/translators:318:5)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:258:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:474:24)

Node.js v22.3.0
> node --experimental-detect-module main.mjs
node:internal/modules/esm/resolve:254
    throw new ERR_UNSUPPORTED_DIR_IMPORT(path, fileURLToPath(base), String(resolved));
          ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'V:\scratch\node_modules\.deno\@[email protected]\node_modules\@mobily\ts-belt\dist\esm\Function' is not supported resolving ES modules imported from V:\scratch\node_modules\.deno\@[email protected]\node_modules\@mobily\ts-belt\dist\esm\index.js
    at finalizeResolution (node:internal/modules/esm/resolve:254:11)
    at moduleResolve (node:internal/modules/esm/resolve:920:10)
    at defaultResolve (node:internal/modules/esm/resolve:1119:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:541:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:510:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:126:49) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///V:/scratch/node_modules/.deno/@[email protected]/node_modules/@mobily/ts-belt/dist/esm/Function'
}

Node.js v22.3.0

The package's ESM export needs to be updated to work or it should be removed and the package should only ship CJS.

Follow mobily/ts-belt#117 for updates.

@dsherret dsherret closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid what appeared to be an issue with Deno wasn't node compat
Projects
None yet
Development

No branches or pull requests

4 participants