cocopon / tweakpane

:control_knobs: Compact GUI for fine-tuning parameters and monitoring value changes
https://tweakpane.github.io/docs/
MIT License
3.69k stars 92 forks source link

ParseError: 'import' and 'export' may appear only with 'sourceType: module' #617

Closed Dragoy closed 3 months ago

Dragoy commented 4 months ago

I'm impotrizing tweakpane as a module, and I get this error!

const { Pane } = require('tweakpane');

D:\Code\my-sketches\node_modules\tweakpane\dist\tweakpane.js:7852
export { BladeApi, ButtonApi, FolderApi, ListBladeApi, ListInputBindingApi, Pane, Semver, SeparatorBladeApi, SliderBladeApi, SliderInputBindingApi, TabApi, TabPageApi, TextBladeApi, TpChangeEvent, VERSION };
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

What can be the problem?

cocopon commented 4 months ago

It depends on your environment (e.g., package.json, package bundler, etc.). Can you provide a minimal reproducible environment for this issue?

Dragoy commented 4 months ago

Yes of course, I use this template for creative coding (https://github.com/mattdesl/canvas-sketch/) and decided to add a library for controllers.

The contents of my package.json:

{
  "name": "my-sketches",
  "version": "1.0.0",
  "description": "",
  "main": "sketch.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "Dragoy",
  "license": "ISC",
  "type": "module",
  "dependencies": {
    "canvas-sketch": "^0.7.7",
    "dat.gui": "^0.7.9",
    "recordrtc": "^5.6.2",
    "three": "^0.147.0",
    "tweakpane": "^4.0.4"
  },
  "devDependencies": {
    "@tweakpane/core": "^2.0.4"
  },
  "parser": "babel-eslint",
  "parserOptions": {
      "sourceType": "module",
      "allowImportExportEverywhere": true
  }
}

I'm new to web development, maybe I'm doing something wrong

cocopon commented 4 months ago

I haven't used canvas-sketch before, so I don't know the details, but the template seems to have a rather unique project structure. It would be best to ask about how to add libraries to the project in the repository's issues section.

If it doesn't support JS modules, you may have to use the previous major version of Tweakpane (3.x). https://tweakpane.github.io/docs/migration/v4/

cocopon commented 3 months ago

Feel free to reopen the issue if you have any updates.