question

celialegend avatar image
celialegend asked

ReferenceError: define is not defined at Script Document

i got this error after i upload my main.js which compiled by my typescript files, my tsconfig.json below:

{
    "compilerOptions": {
      "module": "amd",
      "removeComments": true,
      "preserveConstEnums": true,
      "forceConsistentCasingInFileNames": true,
      "sourceMap": true,
      "rootDir": "./",
      "outFile": "./dist/main.js",
      "baseUrl": "./modules/"
    }
  }
  

there is something like this in js file below:

define("modules/INTERFACES", ["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
});

then i got Error

ReferenceError: define is not defined at Script Document.

thanks for any advice !

CloudScript
14 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Seth Du avatar image Seth Du ♦ commented ·

May I ask are you trying to implement Node.js SDK?

''define is not defined" issue normally should be a tsconfig.json file issue where you set up function modules and yes, your troubleshooting directions should be correct. But we'd like to inform you that we only support PlayFab related issue in the community forum. We suggest you post a thread in a Node.js specialized forum for help.

0 Likes 0 ·
celialegend avatar image celialegend Seth Du ♦ commented ·

thanks for your response, the problem is playfab only supports one js file about cloud script, so i have to compile my js files into one js file. i also tried another solution: i pushed all js files into github, and plabfab combined it automatically, my tsconfig.json is something like below

{
    "compilerOptions": {
      "target": "es5",
      "module": "commonjs",
      "lib": [
        "es2015",
        "es5"],
      "removeComments": true,
      "preserveConstEnums": true,
      "forceConsistentCasingInFileNames": true,
      "rootDir": "./",
      "outDir": "./dist",
      "baseUrl": "./"
    }
  }
  


but it issues another problem, there will be one line: Object.defineProperty(exports, "__esModule", { value: true }); in the first line of my js file, and then playfab got error below:

ReferenceError: exports is not defined !

thanks for any advices!

0 Likes 0 ·
celialegend avatar image celialegend Seth Du ♦ commented ·

by the way, i am not trying to implement Node.js SDK, i am writing typescript code, and then compile them into js file, and then upload it on playfab.

0 Likes 0 ·
Andy avatar image Andy ♦♦ celialegend commented ·

Are you, by any chance, importing anything in your typescript? I believe that won't work without taking additional steps.

1 Like 1 ·
Show more comments
Show more comments

1 Answer

·
celialegend avatar image
celialegend answered

i found the solution, i added the RequireJs file manually into my final one single js file, and the "define" keyword works, everything is going well now, cheers.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.