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

vite CommonJS error #1057

Closed
ewilliam opened this issue May 9, 2024 · 9 comments
Closed

vite CommonJS error #1057

ewilliam opened this issue May 9, 2024 · 9 comments

Comments

@ewilliam
Copy link

ewilliam commented May 9, 2024

Describe the bug

CommonJS issue with recent SvelteKit versions (2.0+ and vite 4.0+)

SyntaxError: [vite] Named export 'Story' not found. The requested module 'inkjs' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'inkjs';
const {Story} = pkg;

recommended default export doesn't work neither

To Reproduce

import { Story } from 'inkjs'

this is all it takes to trigger an error in SvelteKit (presumably any vite app?)

Expected behavior

access to Story export without errors

Ink files

N/A

Environment

  • OS: macOS 14.4.1
  • Node.js version: 20.12.2
  • inklecate version: latest?
  • inkjs version: 2.2.2

Additional Comments

might be helpful/relevant:

https://kit.svelte.dev/docs/faq#how-do-i-fix-the-error-i-m-getting-trying-to-include-a-package

https://publint.dev/[email protected]

@smwhr
Copy link
Collaborator

smwhr commented May 10, 2024

While a fix for this problem is investigated, be aware that ink is known to work with Vite, see : https://github.com/floriancargoet/vite-plugin-ink

@ewilliam
Copy link
Author

thanks - i ended up forking the project and specifying type: module for now https://github.com/ewilliam/inkjs

doubt this works for all cases though

changing es6 output file to .mjs and importing from inkjs/dist/ink-es6.mjs works too

@ewilliam
Copy link
Author

just to add context - looks like vite-plugin-ink doesnt work as is for similar reasons

error when starting dev server:
file:///Users/ewilliam/Projects/inkling/node_modules/.pnpm/[email protected]_inkjs@https+++codeload.github.com+ewilliam+inkjs+tar.gz+f82e13848368065184de7e230e92d38851c49606/node_modules/vite-plugin-ink/dist/index.js:4
import inkjs from "inkjs";
       ^^^^^
SyntaxError: The requested module 'inkjs' does not provide an export named 'default'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
    at async loadConfigFromBundledFile (file:///Users/ewilliam/Projects/inkling/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:68705:21)
    at async loadConfigFromFile (file:///Users/ewilliam/Projects/inkling/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:68558:28)
    at async resolveConfig (file:///Users/ewilliam/Projects/inkling/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:68161:28)
    at async _createServer (file:///Users/ewilliam/Projects/inkling/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:64686:20)
    at async CAC.<anonymous> (file:///Users/ewilliam/Projects/inkling/node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/cli.js:762:24)
 ELIFECYCLE  Command failed with exit code 1.```

@smwhr
Copy link
Collaborator

smwhr commented May 22, 2024

Latest version (2.2.4) should solve all your problems ! Let me know.

@ewilliam
Copy link
Author

yes it does!! thanks so much

@GavanWilhite
Copy link

GavanWilhite commented May 31, 2024

I'm having issues importing Story in next.js
I got it to work in 2.2.3 by doing this:

//@ts-ignore
import { Story } from 'inkjs/dist/ink-full';

I also cannot seem to import Choice anymore like I used to:
import Choice from 'inkjs/ink/engine/Choice';

(This works in 2.2.3)

Thoughts?

@smwhr
Copy link
Collaborator

smwhr commented May 31, 2024

In 2.2.4, you should be able to do

import {Choice} from "inkjs"

and if you need the Compiler

import {Compiler} from "inkjs/full"

There are no improvement between 2.2.3 and 2.2.4 except this change of packaging so if 2.2.3 works,you're better off not changing version

@GavanWilhite
Copy link

Hmm, neither of those work for me in 2.2.4

{
    "compilerOptions": {
        "target": "es2017",
        "lib": ["dom", "dom.iterable", "esnext"],
        "allowJs": true,
        "skipLibCheck": true,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "noEmit": true,
        "esModuleInterop": true,
        "module": "esnext",
        "moduleResolution": "bundler",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "jsx": "preserve",
        "incremental": true,
        "plugins": [
            {
                "name": "next"
            }
        ],
        "paths": {
            "@/*": ["./app/*"]
        }
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
    "exclude": ["node_modules"]
}

I can freeze my version for now, but I'm expecting we'll need to update at some point here

@smwhr
Copy link
Collaborator

smwhr commented May 31, 2024

As of now, there are no scheduled updates of the ink runtime or the inkjs library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants