shaack / cm-chessboard

A JavaScript chessboard without dependencies. Rendered in SVG, coded in ES6. Views FEN, handles move input, animated, responsive, expandable
MIT License
216 stars 68 forks source link

Problems with importing an extension from node.js context #103

Closed shaack closed 1 year ago

blasco commented 1 year ago

Hi, is the package.json properly updated? My project fails to resolve the import of the markers:

This works:

import { Chessboard, INPUT_EVENT_TYPE, COLOR } from 'cm-chessboard';

but the following fails

import { Markers, MARKER_TYPE } from 'cm-chessboard/extensions/markers';

I think it might be related to the package.json of the npm published library.

Thank you for the support!

shaack commented 1 year ago

Hi, which version?

blasco commented 1 year ago
    "cm-chessboard": "^6.0.2",

My guess is that the package.json in the library is only exposing Chessboard and not the extensions, but I'm not sure if that's the real issue and how to solve it.

in cm-chessboard package.json:

  "module": "./src/cm-chessboard/Chessboard.js",

But no references to the extension modules.

This might be related:

https://stackoverflow.com/questions/44345257/import-from-subfolder-of-npm-package

shaack commented 1 year ago

For me this looks mainly like an issue of the used transpiling software or of node.js, because in ES6 you have no imports like import { Chessboard, INPUT_EVENT_TYPE, COLOR } from 'cm-chessboard'; this is transpiling syntax or node.js-syntax. In ES6 you import files with its relative or absolute path and extension (".js").

See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import?retiredLocale=de "[..] The module to import from. The evaluation of the specifier is host-specified. This is often a relative or absolute URL to the .js file containing the module. In Node, extension-less imports often refer to packages in node_modules. Certain bundlers may permit importing files without extensions; check your environment.."

If you find out, how it works with node.js or your transpiler/bundling software, I can add it to the package.json.

blasco commented 1 year ago

Ok, I'll try to figure it out and let you know, thank you!

shaack commented 1 year ago

Nice, thank you. (And I should rename this Issue) 😉

pnb commented 1 year ago

Is this still an issue? I used to have this problem (cm-chessboard v4) but this week I upgraded to take advantage of new v7 features and I am also now able to import from NodeJS without any problems. I am not using all the extensions though, only Markers, PromotionDialog, and a couple custom extensions.

shaack commented 1 year ago

I don't think so and will close the ticket.

Ivanov-Igor-V commented 1 year ago

Hello! Could you explane please. Why import fron line 25 is working, but on 26 - not? image

shaack commented 1 year ago

@Ivanov-Igor-V What do you mean with "is not working". Is there a failure or an exception? Do you use a framework or transpiling software?

Ivanov-Igor-V commented 1 year ago

@Ivanov-Igor-V What do you mean with "is not working". Is there a failure or an exception? Do you use a framework or transpiling software?

i'm sorry its just misspelling in a word extensions