You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to write a music web with this library. I'm a rookie developer so I'm not sure if the following error is my own problem.
I'm trying to import the mode module into my web app so I write this in my html:
<script type="module"> import { Mode } from "./node_modules/@tonaljs/mode/dist/index.js";</script>
(node_modules is a file generated while downloading the tonaljs package and all the modules are in it )
And I got error from my console:
Uncaught SyntaxError: The requested module './node_modules/@tonaljs/mode/dist/index.js' does not provide an export named 'default'
For further info, the following is the index.ts. while running the web on localhost:
import{rotate}from"@tonaljs/collection";import{deprecate,Named,NoteName,transpose}from"@tonaljs/core";import{simplify,transposeFifths}from"@tonaljs/interval";import{EmptyPcset,Pcset}from"@tonaljs/pcset";import{getasgetType}from"@tonaljs/scale-type";constMODES=[[0,2773,0,"ionian","","Maj7","major"],[1,2902,2,"dorian","m","m7"],[2,3418,4,"phrygian","m","m7"],[3,2741,-1,"lydian","","Maj7"],[4,2774,1,"mixolydian","","7"],[5,2906,3,"aeolian","m","m7","minor"],[6,3434,5,"locrian","dim","m7b5"],]asconst;typeModeDatum=typeofMODES[number];exportinterfaceModeextendsPcset{readonlyname: string;readonlymodeNum: number;readonlyalt: number;// number of alterations === number of fithsreadonlytriad: string;readonlyseventh: string;readonlyaliases: string[];}constNoMode: Mode={
...EmptyPcset,name: "",alt: 0,modeNum: NaN,triad: "",seventh: "",aliases: [],};constmodes: Mode[]=MODES.map(toMode);constindex: Record<string,Mode>={};modes.forEach((mode)=>{index[mode.name]=mode;mode.aliases.forEach((alias)=>{index[alias]=mode;});});typeModeLiteral=string|Named;/** * Get a Mode by it's name * * @example * get('dorian') * // => * // { * // intervals: [ '1P', '2M', '3m', '4P', '5P', '6M', '7m' ], * // modeNum: 1, * // chroma: '101101010110', * // normalized: '101101010110', * // name: 'dorian', * // setNum: 2902, * // alt: 2, * // triad: 'm', * // seventh: 'm7', * // aliases: [] * // } */exportfunctionget(name: ModeLiteral): Mode{returntypeofname==="string"
? index[name.toLowerCase()]||NoMode
: name&&name.name
? get(name.name)
: NoMode;}exportconstmode=deprecate("Mode.mode","Mode.get",get);/** * Get a list of all modes */exportfunctionall(){returnmodes.slice();}exportconstentries=deprecate("Mode.mode","Mode.all",all);/** * Get a list of all mode names */exportfunctionnames(){returnmodes.map((mode)=>mode.name);}functiontoMode(mode: ModeDatum): Mode{const[modeNum,setNum,alt,name,triad,seventh,alias]=mode;constaliases=alias ? [alias] : [];constchroma=Number(setNum).toString(2);constintervals=getType(name).intervals;return{empty: false,
intervals,
modeNum,
chroma,normalized: chroma,
name,
setNum,
alt,
triad,
seventh,
aliases,};}exportfunctionnotes(modeName: ModeLiteral,tonic: NoteName){returnget(modeName).intervals.map((ivl)=>transpose(tonic,ivl));}functionchords(chords: string[]){return(modeName: ModeLiteral,tonic: NoteName)=>{constmode=get(modeName);if(mode.empty)return[];consttriads=rotate(mode.modeNum,chords);consttonics=mode.intervals.map((i)=>transpose(tonic,i));returntriads.map((triad,i)=>tonics[i]+triad);};}exportconsttriads=chords(MODES.map((x)=>x[4]));exportconstseventhChords=chords(MODES.map((x)=>x[5]));exportfunctiondistance(destination: ModeLiteral,source: ModeLiteral){constfrom=get(source);constto=get(destination);if(from.empty||to.empty)return"";returnsimplify(transposeFifths("1P",to.alt-from.alt));}exportfunctionrelativeTonic(destination: ModeLiteral,source: ModeLiteral,tonic: NoteName){returntranspose(tonic,distance(destination,source));}exportdefault{
get,
names,
all,
distance,
relativeTonic,
notes,
triads,
seventhChords,// deprecated
entries,
mode,};
And if i do import * as Mode from "./node_modules/@tonaljs/mode/dist/index.js"; ,
it shows the error message : module is not defined
I'm not sure how to fix this.
The text was updated successfully, but these errors were encountered:
I assume you are using a node server? Hard to know exactly what might be causing your issue without seeing your project setup.
The README might have helpful info on how to import Tonal into your project.
I tested both of the examples below and work ok. Hopefully, that helps! 🤝
Hi, I'm trying to write a music web with this library. I'm a rookie developer so I'm not sure if the following error is my own problem.
I'm trying to import the mode module into my web app so I write this in my html:
<script type="module"> import { Mode } from "./node_modules/@tonaljs/mode/dist/index.js";</script>
(node_modules is a file generated while downloading the tonaljs package and all the modules are in it )
And I got error from my console:
Uncaught SyntaxError: The requested module './node_modules/@tonaljs/mode/dist/index.js' does not provide an export named 'default'
For further info, the following is the index.ts. while running the web on localhost:
And if i do
import * as Mode from "./node_modules/@tonaljs/mode/dist/index.js";
,it shows the error message :
module is not defined
I'm not sure how to fix this.
The text was updated successfully, but these errors were encountered: