Skip to content

Error while using mjs import #34

@Xikun201

Description

@Xikun201

Hi everyone,

while importing this module via npm i found following issue:

Using (inside mjs file):
import convertToOpenApi from '@openapi-contrib/json-schema-to-openapi-schema';

Throws following error:
Error [ERR_MODULE_NOT_FOUND] Cannot find module 'Projects/node_modules/@openapi-contrib/json-schema-to-openapi-schema/dist/mjs/const' imported from Projects/node_modules/@openapi-contrib/json-schema-to-openapi-schema/dist/mjs/index.js

This is because for imports the full path is required.

This could be temporarily fixed using:
The --experimental-specifier-resolution=node flag can be used to customize the extension resolution algorithm. The default mode is explicit, which requires the full path to a module be provided to the loader. To enable the automatic extension resolution and importing from directories that include an index file use the node mode.

But this fix is not recommended.

The issue lies inside dist/mjs/index.js. There you can find: import { allowedKeywords } from './const';

This is not valid using plain js without any bundler like webpack or rollup.

Valid would be import { allowedKeywords } from './const.js'; inside the dist/mjs/index.js file.

Thank you for your great work. I hope you can help me fix this problem.

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