Skip to content

An error with npm start: Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:' #432

Description

@Er-hgy

my system is windows
node version: Node.js v18.15.0
database: Postgresql

When I run npm start, something went wrong

C:\Users\a\Desktop\Parse-Server>npm start

parse-server-example@1.4.0 start
node index.js

warn: DeprecationWarning: The Parse Server option 'allowClientClassCreation' default will change to 'false' in a future version.
warn: DeprecationWarning: The Parse Server option 'allowExpiredAuthDataToken' default will change to 'false' in a future version.
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
at new NodeError (node:internal/errors:399:5)
at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1059:11)
at defaultResolve (node:internal/modules/esm/resolve:1135:3)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ESMLoader.import (node:internal/modules/esm/loader:525:22)
at importModuleDynamically (node:internal/modules/cjs/loader:1186:29)
at importModuleDynamicallyWrapper (node:internal/vm/module:429:21)
at importModuleDynamically (node:internal/vm:106:46) {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}
node:internal/process/esm_loader:97
internalBinding('errors').triggerUncaughtException(
^

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
at new NodeError (node:internal/errors:399:5)
at throwIfUnsupportedURLScheme (node:internal/modules/esm/resolve:1059:11)
at defaultResolve (node:internal/modules/esm/resolve:1135:3)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
at ESMLoader.import (node:internal/modules/esm/loader:525:22)
at importModuleDynamically (node:internal/modules/cjs/loader:1186:29)
at importModuleDynamicallyWrapper (node:internal/vm/module:429:21)
at importModuleDynamically (node:internal/vm:106:46) {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

Node.js v18.15.0

Activity

  1. parse-github-assistant commented on Apr 23, 2023

    @parse-github-assistant

    Thanks for opening this issue!

  2. shaobowei88 commented on May 5, 2023

    @shaobowei88

    The same error use Node.js v18.12.1 at windows 10. The node path module path.resolve return path with driver letter,not file:// protocal.
    Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'e:'

    The error is occur at import cloud function,modify node_modules\parse-server\lib\ParseServer.js is running now.o(╥﹏╥)o

            let mypath = path.resolve(process.cwd(), cloud);
            mypath = 'file:///' + mypath.replace(/\\/g, '/');
            if (process.env.npm_package_type === 'module' || ((_json = json) === null || _json === void 0 ? void 0 : _json.type) === 'module') {
                console.log('.....module', mypath)
                await import(mypath);
          } else {
    
                console.log('.....not module', mypath)
    
                require(mypath);
            }
    
  3. youwhoyou commented on Jun 29, 2023

    @youwhoyou

    we are also experiencing this error. Is that a solution for windows users?

  4. mtrezza commented on Jun 29, 2023

    @mtrezza
    Member

    Is this a Parse Server issue, rather than a Parse Server example issue? Where is the problematic code?

  5. justav08 commented on Jun 30, 2023

    @justav08

    Hi, I think it's a Parse Server example issue and the problem is the import of the 'non ES module'-file cloud/main.js because of the error message on start with 'node index.js':

    Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Tools\TestParseServerExample2\cloud\main.js from C:\Tools\TestParseServerExample2\node_modules\parse-server\lib\ParseServer.js not supported.
    main.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
    Instead rename main.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\Tools\TestParseServerExample2\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
    
        at ParseServer.start (C:\Tools\TestParseServerExample2\node_modules\parse-server\lib\ParseServer.js:139:13)
        at async file:///C:/Tools/TestParseServerExample2/index.js:34:3 {
      code: 'ERR_REQUIRE_ESM'
    }
    C:\Tools\TestParseServerExample2\node_modules\parse-server\lib\ParseServer.js:139
                require(path.resolve(process.cwd(), cloud));
                ^
    
    Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Tools\TestParseServerExample2\cloud\main.js from C:\Tools\TestParseServerExample2\node_modules\parse-server\lib\ParseServer.js not supported.
    main.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
    Instead rename main.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in C:\Tools\TestParseServerExample2\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
    
        at ParseServer.start (C:\Tools\TestParseServerExample2\node_modules\parse-server\lib\ParseServer.js:139:13)
        at async file:///C:/Tools/TestParseServerExample2/index.js:34:3 {
      code: 'ERR_REQUIRE_ESM'
    }
    

    so I renamed cloud/main.js to cloud/main.cjs (and deleted the await in the main.cjs because of an additional error) and the example works ...

  6. prafull-opensignlabs commented on Nov 16, 2023

    @prafull-opensignlabs

    spec :
    os: window 11
    package : node 20.9.0
    parse-server-example latest code

    Screenshot 2023-11-16 093734

    In above code I highlighted cloud code line in which I get this same error only on windows and it run perfectly fine on macos what should I do ?

    please help @mtrezza

  7. ok111net commented on Dec 10, 2023

    @ok111net

    @prafull-opensignlabs i miss the same error too!

  8. ok111net commented on Dec 10, 2023

    @ok111net

    this error was resolve:
    this param suport function and string type,change it into function
    1.man.js
    const cloud=function(){ import('./functions.js'); }; export default cloud;
    2.index.js:
    import cloud from './cloud/main.js'; config = { databaseURI: "xxxxx", cloud, ....otherConfigs, }
    @prafull-opensignlabs

  9. prafull-opensignlabs commented on Dec 11, 2023

    @prafull-opensignlabs

    @ok111net work like charm 👍

  10. mtrezza commented on Dec 13, 2023

    @mtrezza
    Member

    Can this issue be closed?

  11. prafull-opensignlabs commented on Dec 13, 2023

    @prafull-opensignlabs

    Can this issue be closed?

    As a mention in documentation of parse server , it's not working in windows that's way instead of that we have to use below code to work windows
    config = { databaseURI: "xxxxx", cloud: cloud: function () { import('./cloud/main.js'); },, ....otherConfigs, }

    so you decide @mtrezza

  12. mtrezza commented on Dec 13, 2023

    @mtrezza
    Member

    Do you suggest a change in the source code or an amendment to the docs?

  13. EhsanParsania commented on Jan 10, 2024

    @EhsanParsania
    Member

    I tried @prafull-opensignlabs code, however it didn't work for me, but if somehow this code works, adding this config as an option to the parse-server-example will be a good idea, since many of the parse-server users use Windows OS @mtrezza

  14. prafull-opensignlabs commented on Jan 10, 2024

    @prafull-opensignlabs

    I tried @prafull-opensignlabs code, however it didn't work for me, but if somehow this code works, adding this config as an option to the parse-server-example will be a good idea, since many of the parse-server users use Windows OS @mtrezza

    I have implement parse server in type : module way instead of common js then it work for me you can try same

  15. prafull-opensignlabs commented on Jan 10, 2024

    @prafull-opensignlabs

    Do you suggest a change in the source code or an amendment to the docs?

    sure

    I have create main.js file which inlcudes my cloud functions
    code from main.js file
    Parse.Cloud.define('myfunc', async(request) =>{
    return "hello world";
    });

    and I have changed this line of code cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js' with below code in index.js which config variable which is pass new ParseServer instance

    const config = {
    databaseURI: 'mongodb://localhost:27017/dev',
    cloud: function () {
    import('./cloud/main.js');
    },
    appId: process.env.APP_ID || 'myAppId',
    masterKey: process.env.MASTER_KEY || '',
    serverURL: process.env.SERVER_URL
    }

    to start server below code use
    const mountPath = process.env.PARSE_MOUNT || '/app';
    const server = new ParseServer(config);
    await server.start();
    app.use(mountPath, server.app);

  16. added a commit that references this issue on Jan 10, 2024
    4151cb0
  17. EhsanParsania commented on Jan 11, 2024

    @EhsanParsania
    Member

    Do you suggest a change in the source code or an amendment to the docs?

    sure

    I have create main.js file which inlcudes my cloud functions code from main.js file Parse.Cloud.define('myfunc', async(request) =>{ return "hello world"; });

    and I have changed this line of code cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js' with below code in index.js which config variable which is pass new ParseServer instance

    const config = { databaseURI: 'mongodb://localhost:27017/dev', cloud: function () { import('./cloud/main.js'); }, appId: process.env.APP_ID || 'myAppId', masterKey: process.env.MASTER_KEY || '', serverURL: process.env.SERVER_URL }

    to start server below code use const mountPath = process.env.PARSE_MOUNT || '/app'; const server = new ParseServer(config); await server.start(); app.use(mountPath, server.app);

    This worked well, thanks @prafull-opensignlabs , but why you've changed /parse to /app for the mountPath?

  18. prafull-opensignlabs commented on Jan 11, 2024

    @prafull-opensignlabs

    Do you suggest a change in the source code or an amendment to the docs?

    sure

    I have create main.js file which inlcudes my cloud functions code from main.js file Parse.Cloud.define('myfunc', async(request) =>{ return "hello world"; });

    and I have changed this line of code cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js' with below code in index.js which config variable which is pass new ParseServer instance

    const config = { databaseURI: 'mongodb://localhost:27017/dev', cloud: function () { import('./cloud/main.js'); }, appId: process.env.APP_ID || 'myAppId', masterKey: process.env.MASTER_KEY || '', serverURL: process.env.SERVER_URL }

    to start server below code use const mountPath = process.env.PARSE_MOUNT || '/app'; const server = new ParseServer(config); await server.start(); app.use(mountPath, server.app);

    This worked well, thanks @prafull-opensignlabs , but why you've changed /parse to /app for the mountPath?

    Because I want parse server on /app route you can change it as per your need

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions