#How can I use import from other directory

25 messages · Page 1 of 1 (latest)

ionic remnant
#
! [20:50:48] [ERR] import { colorTable } from '../lib/data':1: Error loading KubeJS script: server_scripts:colorful_object_recipes.js': identifier is a reserved word: import (server_scripts:colorful_object_recipes.js#1)

server_scripts\colorful_object_recipes.js ```js
import { colorTable } from '../lib/data'

`data\data.js` ```js

// priority: 10000

export const title = (str) => `${str.charAt(0).toUpperCase()}${str.substring(1)}`

export const colorTable = {
  red: 0x861f20,
  orange: 0xd15a00,
  yellow: 0xe2a615,
  light_green: 0x589e17,
  green: 0x455624,
  blue: 0x2a2c8b,
  light_blue: 0x2281c1,
  aqua: 0x146f83,
  purple: 0x5e1f98,
  magenta: 0x9f2f9b,
  pink: 0xc85f8b,
  brown: 0x5a371e,
  black: 0x090b10,
  gray: 0x32353b,
  light_gray: 0x74746e,
  white: 0xc2c8d0
}
plucky islandBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

cobalt spade
#

well

#

in kjs, you don't

#
  1. rhino (the js engine) doesn't support import afaik
#
  1. a variable defined in a file will be available in another of the same type by the time it loads
#

so basically

#

you should just make a script that is loaded basically first (high priority) and it will be available in other scripts of the same type

ionic remnant
cobalt spade
#

data.js

//priority: 10000
let array = ["a string", "bedrock", 12]

log.js

console.log(array[1])
#

the log.js script is able to access the array from data.js because data.js loaded before log.js

drifting valley
#

All your script files will be loaded into one global "file" internally

#

One for each script type, startup/server/client

ionic remnant
#

it work! thx

ionic remnant
cobalt spade
#

no

#

say that you do this in server script

#

you cannot use it in client

#

for that you'd have to use the global object

#

example:

#

startup.js

global.string = "this is a string"

client.js

console.log(global.string)
ionic remnant
#
- const string = "aaa"
+ global.string = "aaa"
```right?
cobalt spade
#

👍

ionic remnant
#

nice